gpt4 book ai didi

c# - 如何将 schemaLocation 属性添加到 XML 文档

转载 作者:行者123 更新时间:2023-11-30 19:18:01 33 4
gpt4 key购买 nike

请查看以下 XML 命名空间和架构位置。

<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>

我已经通过以下方式添加了 namespace ,这似乎工作正常:

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");

但是,如何添加以下模式定位?有什么想法吗?

xsi:schemaLocation="http://services.agresso.com/schema/ABWInvoice/2011/11/14 http://services.agresso.com/schema/ABWInvoice/2011/11/14/ABWInvoice.xsd"

最佳答案

xsi:schemaLocation="..."

不是 namespace 声明:它是一个属性(其值恰好是 namespace ,但没关系)。因此,您可以使用设置属性值的方法添加它。我不熟悉 C# XML API,但它可能是这样的:

XmlElement.SetAttributeValue (localname, prefix, namespace, value)

localname 应该是 "schemaLocation"
前缀 = "xsi"
命名空间 = "http://www.w3.org/2001/XMLSchema-instance"
= “您的架构位置”

关于c# - 如何将 schemaLocation 属性添加到 XML 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14562975/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com