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 6833485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:59:04+00:00 2026-05-26T22:59:04+00:00

I have a stream of xml being returned from a webservice which is coming

  • 0

I have a stream of xml being returned from a webservice which is coming in via HttpWebResponse. Currently I am loading the xml into an XmlTextReader, and then looping through the nodes to grab variables. This works, but is extremely unwieldy, as certain child nodes contain data that affect how I organize the data that comes before it. The XmlTextReader as far as I know, is iterative and forward-reading only. So if child node x contains data that potentially would affect parent node a, I’ve already read through parent node a by the time I get to child node x, and the whole thing is a massive headache.

I am relatively new to working with xml in .net… is there a better way to approach this? I guess thinking out loud, I would love to be able to read the inbound xml stream into an object where I can say: Show me everything in all node x’s : then set them to a class. Based on what they are, okay should me everything in node a’s…. etc, etc. In other words, not a forward reading method, but more of an top down look approach to the entire xml content. Is this possible?

Here is some sample code as to how I’m handling it now:

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
XmlTextReader reader = new XmlTextReader(responseStream);

while (reader.Read())
{
    if (reader.Name == "Whatever")
        {
            var = reader.ReadString();
            reader.Read();

… etc etc until the end of the xml.

Okay, I think I’m almost there, I just need a little more help. Below is my new code, which I am using Linq to XML for, and its working fine. I just have a question about nested data. The final element I am getting out of the xml, “ProductAlignment” actually has child nodes that I need to parse out in a readable format. So right now, with my code the way it is, it takes all of the child elements in ProductAlignment, and jumbles them together in one cell when I databind the whole thing to a gridview. How can I subquery the child elements in ProductAlignment to a more readable format?

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
XDocument xdoc = XDocument.Load(XmlReader.Create(responseStream));
var People= from Person in xdoc.Descendants("Person")
                          where Person.Element("Role").Value != "Admin"
                          orderby Person.Element("Role").Value
                          select new
                          {
                              Role= Person.Element("TerritoryRole").Value,
                              FirstName = Person.Element("FirstName").Value,
                              LastName = Person.Element("LastName").Value,
                              ProductAlignment = Person.Element("ProductAlignment").Value
                          };

        gvTest.DataSource = People;
        gvTest.DataBind();
  • 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-26T22:59:04+00:00Added an answer on May 26, 2026 at 10:59 pm

    you can use linq to xml with following…

    1. load the document using XDocument.Load method
    2. Then you can use XDocument methods to get to your nodes, as specified here
    3. or you could also use XPathSelectElement method to do the old xpath queries on the document if you want.

    this approach would let you traverse in any direction at the cost of whole document being in memory…

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

Sidebar

Related Questions

I have XML that is being returned back from a rest service WCF. The
I have an input stream which is being converted to XML, and read. When
I have a method which returns some xml in a memory stream private MemoryStream
I have a stream of data coming in over the serial line from an
I have an Xml Stream that I'd like to read into an XElement .
I have an object Foo which I serialize to an XML stream. public class
I have response stream from a ftp web request that returns binary file. I
I have a stream of data that I want to place into a container.
I have a stream of bytes which contains a flag which identifies the endianness
I have a JSON stream being generated by a server side C++ program that

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.