CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2011

    Exclamation XML SelectSingleNode failing

    Hi guys,

    I have a XML file that I'm reading as a string and then searching into. The problem is that the SelectSingleNode is failing for any non-root node.

    To access the <HostName> value, I use
    string xmlFile = "<?xml ..............................."; //Has the XML data
    XmlDocument doc = new XmlDocument();

    XmlElement root = doc.DocumentElement;
    XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
    nsmgr.AddNamespace("config", "");

    XmlNode test = root.SelectSingleNode("//config:HostName", nsmgr);

    The above works and prints out "test123" but if I want to select <NIC0><Name>, what do I write? The below failed:

    XmlNode test = root.SelectSingleNode("//config:NIC0/Name", nsmgr);

    My XML is:
    <?xml version="1.0" encoding="utf-16"?>
    <Configuration xmlns:xsd="" xmlns:xsi="" xmlns="">

    <Name>Intel(R) 82567LM Gigabit Network Connection</Name>
    <Manufacturer />

  2. #2
    Join Date
    Jan 2011

    [RESOLVED]: XML SelectSingleNode failing

    I resolved it by using

    XmlNode test = root.SelectSingleNode("/config:Configuration/config:NIC0/config:Name", nsmgr);

    Hope this helps someone!


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width