C # xmldocument selectnodes issue

Source: Internet
Author: User

Hi all,

I have a very simple XSPF file:

<? XML version = "1.0"?>
<Playlist version = "1" xmlns = "http://xspf.org/ns/0/">
<Title> Easter mix </title>
<Info> This is our selection for the Easter period. </INFO>
<Tracklist>
<Track>
<Info> some info </INFO>
<Creator> some creator </creator>
<Title> A title </title>
<Location> location1.mp3 </location>
<Image> some.jpg </image>
</Track>
<Track>
<Info> some info </INFO>
<Creator> some creator </creator>
<Title> A title </title>
<Location> location2.mp3 </location>
<Image> some.jpg </image>
</Track>
</Tracklist>
</Playlist>

 

I am trying to get the title and info elements at the top of the document using

Xmldoc. selectnodes ("/playlist/Title ")

Or

Xmldoc. selectsinglenode ("/playlist/Title ")

But it just doesn't find it. Anybody knows how shoshould I do it?

Many thanks

 

 

Not sure what language you are coding in but your problem is you have a namespace in your XML and you are not querying the XML using it. here is some sample code that shows you how to add a namespace to solve the problem

 
Xmldocument xmldoc =NewXmldocument (); xmldoc. Load ("Playlist. xml"); Xmlnamespacemanager manager =NewXmlnamespacemanager (xmldoc. nametable); manager. addnamespace ("XSPF","Http:// Xspf.org/ns/0 /");String title = xmldoc. selectsinglenode ("// XSPF: Title ", Manager). innertext

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.