I have a XML document:
< xml version="1.0" encoding="utf-8" >
- <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:cc="http://web.resource.org/cc/" xmlns="http://purl.org/rss/1.0/">
<title>etv24.ee - online</title>
<link>http://www.etv24.ee/</link>
<description />
<dc:creator />
<dc:date>2006-04-23T17:05:42+02:00</dc:date>
<rdf:li rdf:resource="http://www.etv24.ee/index.php 0559494" />
<rdf:li rdf:resource="http://www.etv24.ee/index.php 0559493" />
<rdf:li rdf:resource="http://www.etv24.ee/index.php 0559492" />
<rdf:li rdf:resource="http://www.etv24.ee/index.php 0559491" />
<rdf:li rdf:resource="http://www.etv24.ee/index.php 0559490" />
<rdf:li rdf:resource="http://www.etv24.ee/index.php 0559489" />
</rdf:Seq>
</items>
</channel>
<title>Bin Laden: laaneriikide rahvas jagab vastutust Iraagi sojas</title>
<link>http://www.etv24.ee/index.php 0559539</link>
- <![CDATA[
Terrorivorgustiku Al-Qaeda liidri Osama bin Ladeni sonul jagavad laaneriikide kodanikud vastutust "islami vastases sojas."<p>"Soda on vastutus, mida jagavad rahvas ja valitsused," vahendas Reuters Osama bin Ladeni sonu.</p> <p>"Nad saadavad oma pojad sojavakke meiega voitlema ning toetavad seda nii rahaliselt kui moraalselt, samal ajal poletatakse meie maad, pommitatakse meie maju ja tapetakse meie rahvast," utles bin Laden puhapaeval Al-Jazeera telekanalis avaldatud videos.</p>]]>
</description>
<dc:subject>Eesti</dc:subject>
<dc:creator>etv@etv24.ee</dc:creator>
<dc:date>2006-04-23T16:09:00+02:00</dc:date>
</item>
I have tried and tried to read this document but I can't figure it out. Maybe you can help me.
So far I've made code like this:
WebRequest
rssRequest = null;WebResponse rssResponse = null;
Stream rssStream = null;
XmlDocument rssDoc = new XmlDocument();
XmlNamespaceManager nsManager = new XmlNamespaceManager(rssDoc.NameTable);
nsManager.AddNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
XmlNodeList tempNodes = null;
try
{
rssRequest =
WebRequest.Create("http://www.etv24.ee/uudised_rss.php");rssResponse = rssRequest.GetResponse();
rssStream = rssResponse.GetResponseStream();
rssDoc.Load(rssStream);
tempNodes = rssDoc.SelectNodes(
"//rdf:RDF/channel", nsManager); foreach (XmlNode tempNode in tempNodes){
Console.WriteLine(tempNode.Name);}
}
catch (Exception ex){
Console.WriteLine(ex.Message);}
finally{
rssStream.Close();
rssResponse.Close();
}
Console.Read();I think the XPath is wrong, because this code don't show me node names.

Problem with reading XML document
dlamp
If you are sure that all the documents you will process will only have one channel tag, you can safely append an asterisk to the end of your query:
"//rdf:RDF/def:channel/*"
If you are not sure, then you can use the code you are now using to retrieve all the channels and then iterate on the ChildNodes property of each channel in the result.
HTH
--mc
eebarroso
alij
In your query, the "/channel" part looks for a node "channel" with no namespace. The <channel ...> node in your xml does have a namespace, since you defined a default with: xmlns="http://purl.org/rss/1.0/" in your <rdf:RDF ...> tag. So the query fails to find any match. You might have noticed that querying "//rdf:li" did return the elements.
A quick solution is to inform the XmlNamespaceManager about the existence of this namespace, providing your own prefix, for instance, after the other AddNamespace:
nsManager.AddNamespace ("def", "http://purl.org/rss/1.0/");
after this, you will successfully find your channel node, provided that you prefix that with "def":
"//rdf:RDF/def:channel"
Regards
--mc
Nazar Kuliev