I'm trying to find a XML node by searching for an attribute using a substring

65 views Asked by At

First I'm a newbee to C# and XML parsing so please forgive me if my terminology is incorrect. I'm trying to find a node by searching for a particular attribute and value. It will work if the value is exact. I need to be able to search using a substring of the entire attribute value. Here is what I have so far...

 XmlDocument doc1 = new XmlDocument();
        doc1.Load("DVDCollectionExample.xml");

        // Create an XmlNamespaceManager to resolve the default namespace.
        XmlNamespaceManager nsmgr1 = new XmlNamespaceManager(doc1.NameTable);
        nsmgr1.AddNamespace("bk1", "urn:dvd-schema");

        // Select the DVD
        XmlNode DVD;
        XmlElement root1 = doc1.DocumentElement;

        //DVD = root1.SelectSingleNode("descendant::bk1:DVD[bk1:Notes='[filepath disc=2]movies\\Godzilla\\video_ts\\video_ts.ifo[/filepath]'])", nsmgr1);
        DVD = root1.SelectSingleNode("descendant::bk1:DVD[bk1:Notes=Contains(name(),'Godzilla')]", nsmgr1);

The last commented out line will work because it has the exact text of the Notes attribute.

Thanks in advance

0

There are 0 answers