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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:10:08+00:00 2026-06-10T10:10:08+00:00

I’m parsing an xml document, that is like this: <?xml version=1.0 encoding=UTF-8 ?> ….

  • 0

I’m parsing an xml document, that is like this:

<?xml version="1.0" encoding="UTF-8" ?>
....
    <maj>true</maj>
    <data>
        <c>2</c>
        <t>0</t>
        <r>168</r>
        <r>La rentrée Auchan</r>
        <r>0</r>
        <r>2012-08-21 00:00:00</r>
        <r>2012-08-28 00:00:00</r>
        <r>56</r>
        <r>VL</r>

        <c>2</c>
        <t>1</t>
        ...
    </data>

I want to get what there is inside the array “r”, but only the first position 1 the position 5 and 6, and only where t=0
I’ve tried to work like this, I have a listbox that bind the data :

XDocument XMLtxt = JsonConvert.DeserializeXNode(e.Result);

listClients.ItemsSource =
    from c in XMLtxt.Descendants()
    select new JsonB()
    {
        t=c.Element("t").Value.Where(x=>(int) x==0), 
        r1=c.Element("r").Select(..
    }

the jsonB :

 public class JsonB
 {
     public int c { get; set; }
     public int t { get; set; }
     public string r1 { get; set; }
     public int r5 { get; set; }
     public string r6 { get; set; }
     public object[] r { get; set; }
 } 

I really need help, thank you

  • 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-10T10:10:09+00:00Added an answer on June 10, 2026 at 10:10 am

    The XML is a bit ill-structured, so you will have to fix this first with your code.. For starters, in a simple way you can sequentially read/parse the contents so that the structure of the record is clear, and then filter them:

    • prepare a list of JsonB objects – name it i.e. ‘allRecords’
    • prepare a variable of type JsonB – name it i.e. ‘lastRecord’
    • prepare a variable of type int – name it i.e. ‘numberOfRs’
    • get the <data> tag
    • loop over all of its direct children, and for each child:
      • check the name of the child
      • if it is <c>:
        • create new JsobB and put it into lastRecord
        • reset the numberOfRs to zero
        • add the lastRecord to the allRecords list
        • read the c value and put it into lastRecord.c
      • if it is <t>:
        • read the value and put it into lastRecord.t
      • if it is <r>:
        • add 1 to the numberOfRs
        • if numberOfRs is 1, 5 or 6:
        • read the value and put it into lastRecord.r1 or r5 or r6

    this way, you will have a list allRecords with pretty objects, and you can simply .Where(item => item.t ==0) on it.

    However, you may notice it to be very ‘wasteful’ if many of such objects are to be ignored. Then, you could adjust the sequential parser to filter then on-the-fly and thus behave like this

    • prepare a list of JsonB objects – name it i.e. ‘allRecords’
    • prepare a variable of type JsonB – name it i.e. ‘lastRecord’
    • prepare a variable of type int – name it i.e. ‘numberOfRs’
    • prepare a variable of type bool – name it i.e. ‘isInteresting’, preset it to false
    • get the <data> tag
    • loop over all of its direct children, and for each child:
      • check the name of the child
      • if it is <c>:
        • if isInteresting is true
          • add the lastRecord to the allRecords list
        • create new JsobB and put it into lastRecord
        • reset the numberOfRs to zero
        • add the lastRecord to the allRecords list reset the isInteresting to false
        • read the c value and put it into lastRecord.c
      • if it is <t>:
        • read the value and put it into lastRecord.t
        • if it was zero, set the isInteresting to true
      • if it is <r>:
        • add 1 to the numberOfRs
        • if numberOfRs is 1, 5 or 6:
        • read the value and put it into lastRecord.r1 or r5 or r6
    • if isInteresting is true
      • add the lastRecord to the allRecords list

    This way, you will end up with a list that is already filtered and all not interesting items will be GC’ed in the meantime. Please note that the ‘isinteresting – add to list’ is done twice: once before creatig new JsonB, and then also in the final step when all children has been read. If you forget about the check-add after the loop – you may sometimes accidentially skip/ignore the last record.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I know there's a lot of other questions out there that deal with this
I'm parsing an XML file, the creators of it stuck in a bunch social
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.