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

  • Home
  • SEARCH
  • 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 331715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:48:00+00:00 2026-05-12T09:48:00+00:00

I’ve been developing a small xml parser for a specific file with this data

  • 0

I’ve been developing a small xml parser for a specific file with this data structure :

<questionnaire type="Echo">
    <quest etat="0" ord="0">
        <intro>
            <t>bla bla bla</t>
        </intro>
        <rep1>
            <t>word</t>
            <ev id="Q0R1"/>
        </rep1>
        <rep2>
            <t>word</t>
            <ev id="Q0R2"/>
        </rep2>
    </quest>
</questionnaire>

The <quest></quest> tag is repeated 70 times in fact.

Here is the parser I developed in C# and which takes the parameter “xmlString” containing the XML to parse :

XmlTextReader reader = new XmlTextReader(new System.IO.StringReader(xmlString));

while(reader.ReadToFollowing("quest"))
{
    Console.WriteLine("=================================");

    Console.WriteLine("ID : " + reader.GetAttribute("ord").ToString());

    reader.ReadToFollowing("intro");
    reader.ReadToFollowing("t");
    Console.WriteLine("TEXTE : " + reader.ReadString());

    reader.ReadToFollowing("rep1");
    reader.ReadToFollowing("t");
    Console.WriteLine("REPONSE1 : " + reader.ReadString());
    reader.ReadToFollowing("ev");
    Console.WriteLine("CLE1 : " + reader.GetAttribute("id").ToString());

    reader.ReadToFollowing("rep2");
    reader.ReadToFollowing("t");
    Console.WriteLine("REPONSE2 : " + reader.ReadString());
    reader.ReadToFollowing("ev");
    Console.WriteLine("CLE2 : " + reader.GetAttribute("id").ToString());

    Console.WriteLine("ETAT : False");
}

Everything is ok through the 69 first < quest >, but when reaching the 70th, it the fields TEXTE and REPONSE1 are empty and it goes through a NullReferenceException at the line :

Console.WriteLine("CLE1 : " + reader.GetAttribute("id").ToString());

Can anybody tell me what’s wrong ??
Thanks in advance.

  • 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-12T09:48:00+00:00Added an answer on May 12, 2026 at 9:48 am

    Why don’t you use XPath?

    XPathDocument doc = new XPathDocument("sample.xml");
    var navigator = doc.CreateNavigator();
    var iterator = navigator.Select("/questionnaire/quest");
    while (iterator.MoveNext())
    {
        Console.WriteLine("=================================");
    
        Console.WriteLine("ID : " + iterator.Current.GetAttribute("ord", String.Empty));
        var intro = iterator.Current.Select("intro/t");
        if (intro.MoveNext())
        {
            Console.WriteLine("TEXTE : " + intro.Current.Value);
        }
    
        var response1 = iterator.Current.Select("rep1/t");
        if (response1.MoveNext())
        {
            Console.WriteLine("REPONSE1 : " + response1.Current.Value);
        }
    
        var cle1 = iterator.Current.Select("rep1/ev/@id");
        if (cle1.MoveNext())
        {
            Console.WriteLine("CLE1 : " + cle1.Current.Value);
        }
    
        var response2 = iterator.Current.Select("rep2/t");
        if (response2.MoveNext())
        {
            Console.WriteLine("REPONSE2 : " + response2.Current.Value);
        }
    
        var cle2 = iterator.Current.Select("rep2/ev/@id");
        if (cle2.MoveNext())
        {
            Console.WriteLine("CLE2 : " + cle2.Current.Value);
        }
    
        Console.WriteLine("ETAT : False");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 197k
  • Answers 197k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer HMODULE WINAPI LoadLibrary( __in LPCTSTR lpFileName ); It takes a… May 12, 2026 at 7:20 pm
  • Editorial Team
    Editorial Team added an answer You are using a blocking TCP/IP socket, but you are… May 12, 2026 at 7:20 pm
  • Editorial Team
    Editorial Team added an answer Looking through all the registry functions, I found this: SHCopyKey… May 12, 2026 at 7:20 pm

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS
I am currently running into a problem where an element is coming back from

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.