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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:44:34+00:00 2026-06-15T23:44:34+00:00

Let say you have an XML like this: <?xml version=1.0 encoding=utf-8?> <Class HashCode=307960707> <Person>

  • 0

Let say you have an XML like this:

    <?xml version="1.0" encoding="utf-8"?>
<Class HashCode="307960707">
  <Person>
    <Class HashCode="-2020100801">
      <FullName>
        <FirstName>Dan</FirstName>
        <LastName>K</LastName>
      </FullName>
    </Class>
    <Age>20</Age>
    <Class HashCode="-439631396">
      <Address>
        <Street>abc</Street>
        <City>new york</City>
        <ZipCode>30500</ZipCode>
        <PhoneNumber>1245</PhoneNumber>
      </Address>
    </Class>
    <Class HashCode="-1436395737">
      <Person>
        <Class HashCode="-1303968324">
          <FullName>
            <FirstName>katty</FirstName>
            <LastName>G</LastName>
          </FullName>
        </Class>
        <Age>18</Age>
        <Class HashCode="-439631396">
          <Address />
        </Class>
        <Class HashCode="307960707">
          <Person />
        </Class>
      </Person>
    </Class>

I want to be able to iterate only elements with XMLReader in the order they appear, which means class->Person-> class->FullName ,etc..
I was trying to navigate with methods like XMLReader.ReadStartElement() and it didn’t work especially when I read a whitespaces like "\n" which appears to be an element also. :/
I was trying to bypass that whitespace with method XMLReader.Read() with no success.

Please help me understand how should I navigate that way.

  • 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-06-15T23:44:35+00:00Added an answer on June 15, 2026 at 11:44 pm

    XmlReader constructor has an overload that takes an XmlReaderSettings object. The XmlReaderSettings object has an IgnoreWhitespace property.

    In order to read only the next elements you can implement an extension method on XmlReader.

    Here’s an example:

    public static class ExtensionMethods
    {
        public static bool ReadNextElement(this XmlReader reader)
        {
            while (reader.Read())
                if (reader.NodeType == XmlNodeType.Element)
                    return true;
    
            return false;
        }
    }
    

    And here’s a little console application that will demonstrate this:

    public class Program
    {
        public static void Main(string[] args)
        {
            var settings = new XmlReaderSettings();
            settings.IgnoreWhitespace = true;
            settings.IgnoreComments = true;
            settings.IgnoreProcessingInstructions = true;
    
            var reader = XmlReader.Create("XMLFile1.xml", settings);
            while (reader.ReadNextElement())
                Console.WriteLine(reader.Name);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's just say I have an XML file that looks like this: <?xml version=1.0
I have a plist structured like this: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE plist PUBLIC -//Apple//DTD
Let's say that I have something like this in my web.xml file. <filter name=foo>
Let's say I have an XML doc like this: <books> <book>1110</book> <book>1111</book> <book>1112</book> <book>1113</book>
I'm using dom4j to parse my xml. Let's say I have something like this:
Let's say I have some XML like this <channel> <item> <title>This is title 1</title>
Let's say I have an xml file like this: <root> <a><b><c> w </c></b></a> <x><y><z>
Let's say I have an XML something like this: <root xmlns=default xmlns:add=additional> <element foo=fromDefault
my problem is like this. Let's say i have xml like this <root> <child
Let's say I have xml structure like this <root> <element>some content</element> <element>some content 2</element>

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.