如何将 schemaLocation 属性添加到 XML 文档 [英] How to Add schemaLocation attribute to an XML document
问题描述
请查看以下 XML 命名空间和 schemaLocation.
Please view following XML namespace and schemaLocation.
<agr:ABWInvoice
xsi:schemaLocation = "
http://services.agresso.com/schema/ABWInvoice/2011/11/14
http://services.agresso.com/schema/ABWInvoice/2011/11/14/ABWInvoice.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:agrlib = "http://services.agresso.com/schema/ABWSchemaLib/2011/11/14"
xmlns:agr = "http://services.agresso.com/schema/ABWInvoice/2011/11/14"
>
</agr:ABWInvoice>
我通过以下方式添加了命名空间,这似乎工作正常:
I have added namespaces in following way, which seems working fine:
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
ns.Add("agrlib", "http://services.agresso.com/schema/ABWSchemaLib/2011/11/14");
ns.Add("agr", "http://services.agresso.com/schema/ABWInvoice/2011/11/14");
但是,如何添加以下架构位置?有什么想法吗?
But, how to add following schemalocation? Any ideas?
xsi:schemaLocation="http://services.agresso.com/schema/ABWInvoice/2011/11/14 http://services.agresso.com/schema/ABWInvoice/2011/11/14/ABWInvoice.xsd"
推荐答案
xs:schemaLocation="..."
不是命名空间声明:它是一个属性(其值恰好是命名空间,但没关系).因此,您可以使用设置属性值的方法添加它.我不熟悉 C# XML API,但它可能类似于
is not a namespace declaration: it's an attribute (whose value happens to be a namespace, but never mind that). So you would add it with a method that sets an attribute value. I'm not familiar with the C# XML API, but it's probably something like
XmlElement.SetAttributeValue (localname, prefix, namespace, value)
localname
应该是 "schemaLocation"
prefix
= "xsi"
命名空间
= "http://www.w3.org/2001/XMLSchema-instance"
value
= 您的架构位置"
localname
should be "schemaLocation"
prefix
= "xsi"
namespace
= "http://www.w3.org/2001/XMLSchema-instance"
value
= "your schema location"
这篇关于如何将 schemaLocation 属性添加到 XML 文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!