gpt4 book ai didi

c# - XmlNodeList(为什么这个是空的)

转载 作者:数据小太阳 更新时间:2023-10-29 01:53:58 27 4
gpt4 key购买 nike

我不明白为什么这个 NodeList 是空的

XmlDocument document = new XmlDocument();
document.Load(xmlpath);
XmlNodeList nodes = document.SelectNodes("/StructureResponse/rootItem/attributes/Attribute");

这里是 XmlFile

<?xml version="1.0" encoding="utf-8"?>
<StructureResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://nts-de-osm1-pxc/webservices/">
<consolidatedItems xsi:nil="true" xmlns="http://systinet.com/wsdl/com/osm/webservices/service/" />
<rootItem xsi:type="Part" xmlns="http://systinet.com/wsdl/com/osm/webservices/service/">
<attributes>
<Attribute>
<dataDictionary xsi:nil="true" />
<dataType>string</dataType>
<displayName>IDENT_NR</displayName>
<key>true</key><name>IDENT_NR</name>
<searchable>true</searchable>
<userAttribute>true</userAttribute>
<value>9662744</value>
</Attribute>
<Attribute>
<dataDictionary xsi:nil="true" />
<dataType>string</dataType>
<displayName>AI</displayName>
<key>true</key><name>AI</name>
<searchable>true</searchable>
<userAttribute>true</userAttribute>
<value>00</value>
</Attribute>
</rootItem>
</StructureResponse>

在最终脚本中,我想获得一个数组字符串,其中包含其中的每个属性。

谢谢斯特凡

最佳答案

您没有考虑文档中的 XML 命名空间 (xmlns="http://nts-de-osm1-pxc/webservices/")!

好的,您甚至有两个独立的命名空间 - 更新了我的示例。

试试这个:

XmlDocument document = new XmlDocument();
document.Load(xmlpath);

XmlNamespaceManager mgr = new XmlNamespaceManager(document.NameTable);
mgr.AddNamespace("ns", "http://nts-de-osm1-pxc/webservices/");
mgr.AddNamespace("root", "http://systinet.com/wsdl/com/osm/webservices/service/");

XmlNodeList nodes = document.SelectNodes("/ns:StructureResponse/root:rootItem/root:attributes/root:Attribute", mgr);

马克

关于c# - XmlNodeList(为什么这个是空的),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1592612/

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