XML SelectSingleNode failing
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: XML SelectSingleNode failing

  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", "http://tempuri.org/ConfigSchema.xsd");

    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="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/ConfigSchema.xsd">

    <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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a Codeguru.com survey!

HTML5 Development Center