Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6688941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:27:41+00:00 2026-05-26T05:27:41+00:00

I am parsing an XML document to pull out the first occurrence of content

  • 0

I am parsing an XML document to pull out the first occurrence of “content” node and read the inner text for that node.

The XML file coming in can be seen at:

https://www.googleapis.com/shopping/search/v1/public/products?key=AIzaSyAfaLdRHGKa5Rens–Vpw-KftdzWyxe2co&country=GB&q=5055277014187&alt=atom

The code behind that processes the file is:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestToSend);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream());
string responseString = sr.ReadToEnd();

XmlDocument thisXmlDoc = new XmlDocument();
thisXmlDoc.LoadXml(responseString);

//get Companies
XmlNodeList ocNodesCompany = thisXmlDoc.SelectNodes("//feed/entry/content");
foreach (XmlElement element in ocNodesCompany)
{
    description = element.InnerText;
    testOutput = "<b>" + stockRow["stockitem_text"].ToString() + "</b>: " + description + "<br /><br />";
    break;
}

Response.Write(responseString + "<br /><br />" + testOutput);

Unfortunately even though the XML file is coming through correctly, it is not finding any nodes and therefore returning NULL and not entering the ‘foreach’ loop.

Thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:27:42+00:00Added an answer on May 26, 2026 at 5:27 am

    When using XPath queries for elements that are in some namespace, you have to declare and use namespace prefix.

    The following code works:

    var nsmgr = new XmlNamespaceManager(new NameTable());
    nsmgr.AddNamespace("atom", "http://www.w3.org/2005/Atom");
    
    XmlNodeList ocNodesCompany =
        thisXmlDoc.SelectNodes("/atom:feed/atom:entry/atom:content", nsmgr);
    

    Also, when referring to the root node, you should use / instead of //.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing large XML document using pull parser ( org.xmlpull.v1.XmlPullParser ). When I reach
I've been trying to read a node in an xml file generated from DSLR
I am parsing a XML document with XmlDocument. When the source file contains <template>
I have an XML document coming in over a socket that I need to
I am parsing an XML document that is in UTF-8 format as follows: XDocument
I get the followinng Xresponse after parsing the XML document: <DIDL-Lite xmlns=urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/ xmlns:dc=http://purl.org/dc/elements/1.1/ xmlns:upnp=urn:schemas-upnp-org:metadata-1-0/upnp/
I parse a big xml document with Sax, I want to stop parsing the
What is the antonyms of parsing in terms of XML document. For Example: When
this is my first time using StAX for parsing XML documents (still in the
I am parsing XML Document using SAX Parser. I want to know which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.