Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / March 2008

Tip: Looking for answers? Try searching our database.

Trouble getting an XmlNodeList from flickr atom feed

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alun - 17 Mar 2008 13:50 GMT
Hi Guys,

I'm having some trouble selecting the some XML nodes from a Flickr
atom feed.  He's the a cut down version of the code to illustrate my
problem:

using System.Xml;

protected void Page_Load(object sender, EventArgs e)

{

      XmlDocument xmlDoc = new XmlDocument();

     HttpWebRequest webRequest =
(HttpWebRequest)WebRequest.Create("http://api.flickr.com/services/
feeds/photos_public.gne");
     webRequest.Timeout = 10000;

     // Makes sure the connection is not persistant
     webRequest.KeepAlive = false;
     HttpWebResponse webResponse = null;

    webResponse = (HttpWebResponse)webRequest.GetResponse();

     xmlDoc.Load(webResponse.GetResponseStream());

     XmlNamespaceManager NsMgr = new
XmlNamespaceManager(xmlDoc.NameTable);

     NsMgr.AddNamespace("", "http://www.w3.org/2005/Atom");
     NsMgr.AddNamespace("dc", "http://purl.org/dc/elements/1.1/");

     XmlElement root = xmlDoc.DocumentElement;
    // XmlNodeList nodeList1 =  root.
     XmlNodeList nodeList =   root.SelectNodes("/feed/entry", NsMgr);

     Response.Write("The number of nodes is:" + nodeList.Count);

}

When debugging the atom feed is loaded into the 'root' XmlElement. But
then  I can't seem to select the nodes with my Xpath query.

Thanks for any assistance.

Alun
Martin Honnen - 17 Mar 2008 14:51 GMT
>       xmlDoc.Load(webResponse.GetResponseStream());
>
>       XmlNamespaceManager NsMgr = new
> XmlNamespaceManager(xmlDoc.NameTable);
>
>       NsMgr.AddNamespace("", "http://www.w3.org/2005/Atom");

You need to bind a prefix to the default namespace e.g
        NsMgr.AddNamespace("atom", "http://www.w3.org/2005/Atom");
then use that prefix in your XPath expressions e.g.

  XmlNodeList nodeList =   xmlDoc.SelectNodes("/atom:feed/atom:entry",
NsMgr);

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.