gpt4 book ai didi

c# - XmlNodeList 仍然是空的——为什么会这样?

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

好吧,这已经让我忙了几个小时了,但我仍然无法解释:我的 XML 是这样开始的:

<?xml version="1.0" encoding="iso-8859-1"?>
<ISO15745Profile xmlns="http://www.profibus.com/GSDML/2003/11/DeviceProfile" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.profibus.com/GSDML/2003/11/DeviceProfile ..\XSD\GSDML-DeviceProfile-v2.1.xsd">
<ProfileHeader>
<ProfileIdentification>PROFINET Device Profile</ProfileIdentification>
<ProfileRevision>1.00</ProfileRevision>
<ProfileName>Device Profile for PROFINET Devices</ProfileName>
<ProfileSource>PROFIBUS Nutzerorganisation e. V. (PNO)</ProfileSource>
<ProfileClassID>Device</ProfileClassID>
<ISO15745Reference>
<ISO15745Part>4</ISO15745Part>
<ISO15745Edition>1</ISO15745Edition>
<ProfileTechnology>GSDML</ProfileTechnology>
</ISO15745Reference>
</ProfileHeader>
<ProfileBody>
<DeviceIdentity DeviceID="0x000A" VendorID="0x00B0">
<InfoText TextId="InfoTextId1"/>
<VendorName Value="Phoenix Contact GmbH"/>
</DeviceIdentity>
<DeviceFunction>
<Family MainFamily="I/O" ProductFamily="Inline"/>
</DeviceFunction>
<ApplicationProcess>
<DeviceAccessPointList>
<DeviceAccessPointItem ID="DIM 1" FixedInSlots="0" PhysicalSlots="0..64" MinDeviceInterval="32" ModuleIdentNumber="0x00000300" DNS_CompatibleName="IL-PN-BK-2TX" ImplementationType="ERTEC200" ObjectUUID_LocalIndex="1">
<ModuleInfo>
<Name TextId="IL PN BK DI8 DO4 2TX"/>
<InfoText TextId="InfoTextId1"/>
<VendorName Value="Phoenix Contact"/>
<OrderNumber Value="2703994"/>
</ModuleInfo>
<SubslotList>
<SubslotItem SubslotNumber="32768" TextId="SubSlot_Interface"/>
<SubslotItem SubslotNumber="32769" TextId="SubSlot_Port1"/>
<SubslotItem SubslotNumber="32770" TextId="SubSlot_Port2"/>
</SubslotList>
<IOConfigData MaxInputLength="512" MaxOutputLength="512"/>
<UseableModules>
<ModuleItemRef FixedInSlots="1" ModuleItemTarget="1"/>
<ModuleItemRef AllowedInSlots="4..64" ModuleItemTarget="2"/>
<ModuleItemRef AllowedInSlots="4..64" ModuleItemTarget="3"/>
<ModuleItemRef AllowedInSlots="4..64" ModuleItemTarget="4"/>
<ModuleItemRef AllowedInSlots="4..64" ModuleItemTarget="5"/>
<ModuleItemRef AllowedInSlots="4..64" ModuleItemTarget="6"/>
...

现在我要做的是使用 AllowedInSlots,但是在创建 XmlNodeList 时使用

XmlDocument gsdml = new XmlDocument();
gsdml.Load(fpfad);

XmlNodeList ModuleItemRef = gsdml.SelectNodes("/ISO15745Profile/ProfileBody/ApplicationProcess/DeviceAccessPointList/DeviceAccessPointItem/UseableModules");

XmlNodeList 保持为空。我究竟做错了什么?我想也许我必须与 Namespacemanager 一起工作并尝试过,但那没有做任何事情。

这是我之前尝试过的:

XmlDocument gsdml = new XmlDocument();
gsdml.Load(fpfad);

XmlNamespaceManager mgr = new XmlNamespaceManager(gsdml.NameTable);
mgr.AddNamespace("iso", "http://www.profibus.com/GSDML/2003/11/DeviceProfile");
XmlNodeList ModuleItemRef = gsdml.SelectNodes("/iso:ISO15745Profile/ProfileBody/ApplicationProcess/DeviceAccessPointList/DeviceAccessPointItem/UseableModules", mgr);

不过它没有用,所以一定是哪里出了问题。

第二次编辑:在路径的每一部分都包含前缀就可以了。

最佳答案

确实是命名空间管理器。

xmlns="http://www.profibus.com/GSDML/2003/11/DeviceProfile"

意味着一切都在那个命名空间中(除非声明了另一个默认值,或者一个元素声明了它自己的命名空间)。您将需要使用 namespace 管理器在该 namespace 中进行搜索。

关于c# - XmlNodeList 仍然是空的——为什么会这样?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8235493/

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