Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Read in an XML file that has a namespace defined

Posted on 2013-01-07
2
Medium Priority
?
337 Views
Last Modified: 2013-01-07
Hi Experts,

I have the below XML file which I cannot change!

<?xml version='1.0'?>
<Motorola xmlns:Falcon='http://www.domain.com/RFID/Readers/Config/Falcon' xmlns='http://www.domain.com/RFID/Readers/Config/Falcon'>
<Config>
<AppVersion major='2' minor='2' build='0' maintenance='5'/>
<CommConfig DHCP='0' IPAddr='192.168.1.33' Mask='255.255.255.0' Gateway='0.0.0.0' DNS='0.0.0.0' HttpRunning='1' TelnetActive='1' FtpActive='1' usbMode='1' WatchdogEnabled='1' SerialConTimeout='0' SNTP='192.168.1.152' SNTPHostName='ZACH-PC' sntpHostDisplayMode='1' llrpClientMode='0' llrpPort='5084' llrpHostIP='192.168.127.2' allowllrpConnOverride='0'/>
<RegionConfig RFBoard='0' RFCountry='United States' RFRegulatory='US FCC 15' RFScanMode='0' LBTEnable='0' ChannelData='FFFFFFFFFFFFFFFF' MACLinkProfile='65535'/>
<SnmpConfig snmpVersion='1' heartbeat='1' epcgReadPointOperStateNotifyEnable='15' epcgReadPointOperNotifyFromState='0' epcgReadPointOperNotifyToState='0' epcgReadPointOperNotifyStateLevel='28080' epcgAntRdPntReadFailureNotifEnable='15' epcgAntRdPntReadFailureNotifLevel='28080' epcgAntRdPntWriteFailureNotifEnable='15' epcgAntRdPntWriteFailureNotifLevel='28080' epcgAntRdPntKillFailureNotifEnable='15' epcgAntRdPntKillFailureNotifLevel='28080' epcgAntRdPntEraseFailureNotifEnable='15' epcgAntRdPntEraseFailureNotifLevel='28080' epcgAntRdPntLockFailureNotifEnable='15' epcgAntRdPntLockFailureNotifLevel='28080' epcgIoPortOperStatusNotifEnable='15' epcgIoPortOperStatusNotifLevel='28080' epcgRdrDevOperNotifStateLevel='6' epcgRdrDevOperStateEnable='1' epcgRdrDevOperNotifFromState='0' epcgRdrDevOperNotifToState='0'/>
<UserList>
<User name='admin' accessLevel='3' PSWD='DADBE0EE74A6528E'/>
</UserList>
<IPReader name='Advanced Reader' desc='Advanced Reader' flags='0' MonoStatic='0' CheckAntenna='1' gpiDebounceTime='0' contact='Company Inc'>
<ReadPoint name='Read Point 1' flags='0'/>
<ReadPoint name='Read Point 2' flags='1'/>
<ReadPoint name='Read Point 3' flags='1'/>
<ReadPoint name='Read Point 4' flags='1'/>
<ReadPoint name='Read Point 5' flags='0'/>
<ReadPoint name='Read Point 6' flags='0'/>
<ReadPoint name='Read Point 7' flags='0'/>
</IPReader>
</Config>
<MOTOROLA_LLRP_CONFIG><LLRP_READER_CONFIG />
</MOTOROLA_LLRP_CONFIG>
<RadioProfileData><RadioRegisterData Address='ffffffff' Data='0'/>
</RadioProfileData>
<CustomProfileData ForceEAPMode='0' MaxNumberOfTagsBuffered='512' EnableDefaultFilter='false'/>
</Motorola >

Open in new window


How can I read in and/or set the value of Motorola.Config.CommConfig.IPAddr?  I tried this but it doesn't seem to work:

                   XmlDocument document = new XmlDocument();
                    document.Load(path);
                    XmlElement xmlRoot = document.DocumentElement;

                    XmlNode node = xmlRoot.SelectSingleNode("/Config/CommConfig");

Open in new window


node comes back as null! Eventhough, I can see that Motorola has a child node called Config

Thanks
0
Comment
Question by:axnst2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 38752051
Use  an XmlNamespaceManager, and assign an artificial prefix when selecting. Also, adjust your XPath--you are not accounting for the root node:

e.g.

using System.Xml;

namespace ConsoleApplication52
{
    class Program
    {
        private static string path = "input.xml";

        static void Main(string[] args)
        {
            XmlDocument document = new XmlDocument();
            XmlNamespaceManager mgr = new XmlNamespaceManager(document.NameTable);

            mgr.AddNamespace("pre", "http://www.domain.com/RFID/Readers/Config/Falcon");
            document.Load(path);

            XmlElement xmlRoot = document.DocumentElement;
            XmlNode node = xmlRoot.SelectSingleNode("//pre:Config/pre:CommConfig", mgr);
        }
    }
}

Open in new window

0
 

Author Closing Comment

by:axnst2
ID: 38752144
Perfect!  Worked like a charm!  Thanks!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question