请查看以下XML命名空间和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>
我已经按照以下方式添加了命名空间,这似乎工作正常:
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");
但是,如何添加以下schemalocation?有什么想法吗?
xsi:schemaLocation="http://services.agresso.com/schema/ABWInvoice/2011/11/14 http://services.agresso.com/schema/ABWInvoice/2011/11/14/ABWInvoice.xsd"
答案 0 :(得分:4)
xs:schemaLocation="..."
不是命名空间声明:它是一个属性(其值恰好是命名空间,但不要紧,)。因此,您可以使用设置属性值的方法添加它。我不熟悉C#XML API,但它可能类似于
XmlElement.SetAttributeValue (localname, prefix, namespace, value)
localname
应为"schemaLocation"
prefix
= "xsi"
namespace
= "http://www.w3.org/2001/XMLSchema-instance"
value
= "your schema location"
答案 1 :(得分:3)
迈克的回答引导我得到以下答案:
[XmlAttributeAttribute("schemaLocation", AttributeName = "schemaLocation",
Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string SchemaLocation = "http://services.agresso.com/schema/ABWInvoice/2011/11/14 http://services.agresso.com/schema/ABWInvoice/2011/11/14/ABWInvoice.xsd";
答案 2 :(得分:0)
只需在您的课程中添加此代码
即可公共部分类MyClass {
[XmlAttribute(Namespace = System.Xml.Schema.XmlSchema.InstanceNamespace)]
public string schemaLocation = "http://www.adap.cx/m3/x4 lksdjv45.xsd";
... }