XmlNodeList remains empty - why is that so?

3

Okay, this had me occupied for several hours now and still I have no explanation for it: My XML starts like this:

<?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"/>
...

Now what I'm trying to do is work with the AllowedInSlots, but when creating a XmlNodeList with

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

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

that XmlNodeList remains empty. What am I doing wrong? I thought that maybe I had to work with the Namespacemanager and tried that, but that didn't do anything.

This is what I tried earlier:

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

It didn't work, though, so something there has to be wrong.

2nd Edit: Including the prefix with every part of the path did the trick.

c#
xml
asked on Stack Overflow Nov 22, 2011 by Stefan • edited Nov 23, 2011 by Stefan

1 Answer

3

It is indeed the namespace manager.

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

means that everything is in that namespace (unless another default is declared, or an element declares its own namespace). You will need to use a namespace manager to search in that namespace.

answered on Stack Overflow Nov 22, 2011 by Kyle W

User contributions licensed under CC BY-SA 3.0