•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the XML, XSLT and XPATH section within the Software Development category of DaniWeb, a massive community of 456,533 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,877 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our XML, XSLT and XPATH advertiser: Programming Forums
Views: 2845 | Replies: 1 | Solved
![]() |
•
•
Join Date: Aug 2006
Posts: 57
Reputation:
Rep Power: 3
Solved Threads: 0
hi all,
i have the following xml file.
<rss version="2.0" xmlns:media="http://tools.search.yahoo.com/mrss/" >
<channel>
<title>SWF media</title>
<link>http://www.blogdigger.com/media/</link>
<description>Recent .swf files found by Blogdigger</description>
<item>
<title>Dollar Bus Rolls Into Town</title>
<link>http://feeds.feedburner.com/Chicagoist?m=1115</link>
<description>some description</description>
<pubDate>Thu, 23 Mar 2006 14:11:57 EST</pubDate>
<enclosure url="http://www.kitschn.com/flash/MenuCoverPage-DrinksMenu09-05.swf" type="application/x-shockwave-flash"/>
<media:content url="http://www.kitschn.com/flash/MenuCoverPage-DrinksMenu09-05.swf" type="application/x-shockwave-flash"/>
</item>
<item>
<title>E-mail</title>
<link>http://billarnold.typepad.com/poet_in_motion/2006/03/email.html</link>
<description>description 2/description>
<pubDate>Wed, 22 Mar 2006 17:28:28 EST</pubDate>
<enclosure url="http://www.softlab.ece.ntua.gr/~sivann/pub/swf/may02-smilepop-soapbox4.swf" type="application/x-shockwave-flash"/>
<media:content url="http://www.softlab.ece.ntua.gr/~sivann/pub/swf/may02-smilepop-soapbox4.swf" type="application/x-shockwave-flash"/>
</item>
</channel>
</rss>
i am using xpath to navigate through this xml file.
i used the following code to navigate through items node.
XmlDocument doc = new XmlDocument();
doc.Load(xmlfile);
XPathNavigator nav = doc.CreateNavigator();
XPathExpression exp = nav.Compile("rss/channel/item");
XPathNodeIterator iterator = nav.Select(exp);
XPathNodeIterator iter1;
while (iterator.MoveNext())
{
iter1 = iterator.Current.SelectChildren("media:content", "");
if (iter1.Count > 0)
{
while (iter1.MoveNext())
{
if (iter1.Current.HasAttributes == true)
{
string url = iter1.Current.GetAttribute("url", "");
}
}
}
}
but when i execute the code, the iter1.count always returns zero. if i select anyother children(like title or description)i am able to display the value.but when i select media:content(one of the subitems of item) i am not able to display the attribute value.
Where am i going wrong?
Any suggestions please
regards
Exelio
i have the following xml file.
<rss version="2.0" xmlns:media="http://tools.search.yahoo.com/mrss/" >
<channel>
<title>SWF media</title>
<link>http://www.blogdigger.com/media/</link>
<description>Recent .swf files found by Blogdigger</description>
<item>
<title>Dollar Bus Rolls Into Town</title>
<link>http://feeds.feedburner.com/Chicagoist?m=1115</link>
<description>some description</description>
<pubDate>Thu, 23 Mar 2006 14:11:57 EST</pubDate>
<enclosure url="http://www.kitschn.com/flash/MenuCoverPage-DrinksMenu09-05.swf" type="application/x-shockwave-flash"/>
<media:content url="http://www.kitschn.com/flash/MenuCoverPage-DrinksMenu09-05.swf" type="application/x-shockwave-flash"/>
</item>
<item>
<title>E-mail</title>
<link>http://billarnold.typepad.com/poet_in_motion/2006/03/email.html</link>
<description>description 2/description>
<pubDate>Wed, 22 Mar 2006 17:28:28 EST</pubDate>
<enclosure url="http://www.softlab.ece.ntua.gr/~sivann/pub/swf/may02-smilepop-soapbox4.swf" type="application/x-shockwave-flash"/>
<media:content url="http://www.softlab.ece.ntua.gr/~sivann/pub/swf/may02-smilepop-soapbox4.swf" type="application/x-shockwave-flash"/>
</item>
</channel>
</rss>
i am using xpath to navigate through this xml file.
i used the following code to navigate through items node.
XmlDocument doc = new XmlDocument();
doc.Load(xmlfile);
XPathNavigator nav = doc.CreateNavigator();
XPathExpression exp = nav.Compile("rss/channel/item");
XPathNodeIterator iterator = nav.Select(exp);
XPathNodeIterator iter1;
while (iterator.MoveNext())
{
iter1 = iterator.Current.SelectChildren("media:content", "");
if (iter1.Count > 0)
{
while (iter1.MoveNext())
{
if (iter1.Current.HasAttributes == true)
{
string url = iter1.Current.GetAttribute("url", "");
}
}
}
}
but when i execute the code, the iter1.count always returns zero. if i select anyother children(like title or description)i am able to display the value.but when i select media:content(one of the subitems of item) i am not able to display the attribute value.
Where am i going wrong?
Any suggestions please
regards
Exelio
![]() |
•
•
•
•
•
•
•
•
DaniWeb XML, XSLT and XPATH Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- [urgent] HTML form => XML file (JSP)
- How to store and search a XML FIle (ASP.NET)
- Cannot load XML file. (PHP)
- Parsing xml file (Python)
- saving xml file from servlet request instance (Java)
- Unzip zipped xml file (VB.NET)
- problem reading xml file in c# (C#)
- parsing error (XML file-java-schema) (Java)
- Pass XML file contents to a hash table. (Java)
Other Threads in the XML, XSLT and XPATH Forum
- Previous Thread: Looking for ExamXML features in a free application.
- Next Thread: Newbie question, schema, complex types and unordered multiple elemets


Linear Mode