Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# XmlNodeList仍然为空—为什么会这样?_C#_Xml - Fatal编程技术网

C# XmlNodeList仍然为空—为什么会这样?

C# XmlNodeList仍然为空—为什么会这样?,c#,xml,C#,Xml,好吧,这件事让我忙了好几个小时,但我仍然没有解释: 我的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://

好吧,这件事让我忙了好几个小时,但我仍然没有解释: 我的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"/>
...
该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"

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

好的,编辑问题以包含我试图处理该问题的(错误?)代码。再次编辑(最终使其正常工作)。谢谢你的帮助,如果你不告诉我名称空间是问题所在,我会先尝试很多其他方法。你在问题的第二个问题中写下了答案,但我会在这里重写,以供将来的任何人使用。您必须在每个部分上指定名称空间:“/iso:ISO15745Profile/iso:ProfileBody/iso:ApplicationProcess…”
xmlns="http://www.profibus.com/GSDML/2003/11/DeviceProfile"