xpath won't give back xml-node when attribute is added

Hello
 
I have the following xml-document

< xml version="1.0" encoding="utf-8" >

<DIDL xmlns="urn:mpeg:mpeg21:2002:02-DIDL-NS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<Item>

<Descriptor>

<Statement mimeType="text/xml">

<SomeXML/>

</Statement>

</Descriptor>

</Item>

</DIDL>

in the XmlNode node.

When I

ns = new XmlNamespaceManager(new NameTable());

ns.AddNamespace("mpeg7", "urn:mpeg:mpeg7:schema:2001"); // used in SomeXml

ns.AddNamespace("didl","urn:mpeg:mpeg21:2002:02-DIDL-NS");

ns.AddNamespace("dia", "urn:mpeg:mpeg21:2003:01-DIA-NS" ); // used in SomeXml

ns.AddNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");

string xpath =

"/didl:DIDL/didl:Item/didl:Descriptor/didl:Statement";

XmlNode hresNode = node.SelectSingleNode(xpath, ns);

execute this code, I get the Statement node.

If I change the x-path expression to:

string xpath =

"/didl:DIDL/didl:Item/didl:Descriptor/didl:Statement[@didl:mimeType='text/xml']";

it does not work anymore.

Thanks for your suggestions,

MT

 

 

 




Answer this question

xpath won't give back xml-node when attribute is added

  • mahricky

    Great, thanks !

    MT

  • randy.liden

    Ooops, I meant of course

    "/didl:DIDL/didl:Item/didl:Descriptor/didl:Statement[@mimeType='text/xml']";

  • Pete Claar

    Thanks for your answer, but that does not do the trick.

    Any other suggestions


    MT

  • Roman Benko

    Default namespace declaration (xmlns=...) only affects elements and not attributes. mimeType attribute in your XML is in no namespace, so you should use
    "/didl:DIDL/didl:Item/didl:Descriptor/didl:Statement[mimeType='text/xml']";


  • xpath won't give back xml-node when attribute is added