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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:25:30+00:00 2026-05-23T09:25:30+00:00

I don’t want to use XMLDocument because i’ve written the XML Writing code using

  • 0

I don’t want to use XMLDocument because i’ve written the XML Writing code using XMLWriter. So there should be no reason why to switch.

<Player>
  <Friends />
  <Ignores>
    <Ignore>117779</Ignore>
    <Ignore>44237636758361374</Ignore>
    <Ignore>564534831</Ignore>
  </Ignores>
  <InventoryItems>
    <Item>
      <Slot>0</Slot>
      <Id>995</Id>
      <Amount>39493</Amount>
    </Item>
    <Item>
      <Slot>27</Slot>
      <Id>1049</Id>
      <Amount>12</Amount>
    </Item>
  </InventoryItems>
  <BankItems />
</Player>

I’m trying to parse that out there. Here is what I got so far. Seems to break everywhere I had it working a bit with <Ignore>'s but thats when I used ReadToFollowing instead of ReadToNextSibling, it would work until ReadToFollowing hit a empty line.. and it would just hit up to EOF.

XmlTextReader reader = new XmlTextReader(misc.getServerPath() + "\\accounts\\" + username + ".xml");
while (reader.Read())
{
    if (reader.NodeType == XmlNodeType.Element && reader.Name == "Friends") {
        if (!reader.IsEmptyElement) //got any friends
        {
            while (reader.ReadToFollowing("Friend"))
                //do_stuff_with_that_data(reader.ReadElementContentAsLong());
        }
    } else if (reader.NodeType == XmlNodeType.Element && reader.Name == "Ignores") {
        if (!reader.IsEmptyElement) //got any ignores
        {
            reader.ReadToFollowing("Ignore");
            while (reader.ReadToNextSibling("Ignore"))
            {
                //do_stuff_with_that_data(reader.ReadElementContentAsLong());
            }
        }
    } else if (reader.NodeType == XmlNodeType.Element && reader.Name == "InventoryItems") {
        if (!reader.IsEmptyElement) //got items
        {
            int slot, id, amount;
            while (reader.ReadToNextSibling("Item"))
            {
                reader.ReadToFollowing("Slot");
                slot = reader.ReadElementContentAsInt();
                reader.ReadToFollowing("Id");
                id = reader.ReadElementContentAsInt();
                reader.ReadToFollowing("Amount");
                amount = reader.ReadElementContentAsInt();
                //do_stuff_with_that_data(slot, id, amount);
            }
        }
    } else if (reader.NodeType == XmlNodeType.Element && reader.Name == "BankItems") {
        if (!reader.IsEmptyElement) //got bank items
        {
            int slot, id, amount;
            while (reader.ReadToNextSibling("Item"))
            {
                reader.ReadToFollowing("Slot");
                slot = reader.ReadElementContentAsInt();
                reader.ReadToFollowing("Id");
                id = reader.ReadElementContentAsInt();
                reader.ReadToFollowing("Amount");
                amount = reader.ReadElementContentAsInt();
                //do_stuff_with_that_data(slot, id, amount);
            }
        }
    }   
  • 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-23T09:25:30+00:00Added an answer on May 23, 2026 at 9:25 am

    So there should be no reason why to switch.

    There’s a very good reason to switch to a DOM-style representation unless your documents are too large to reasonably fit in memory: it’s much easier to work with that representation.

    XmlReader is frankly a pain to use. It’s not clear exactly what’s wrong (you say it “seems to break everywhere” but not exactly what’s happening) but I would strongly advise you to move to a simpler model. Your code will be considerably simpler afterwards. If you can possibly use LINQ to XML instead of the pre-3.5 API, that will make your life even better.

    If you absolutely insist on using XmlReader, I suggest you update your post with a simpler piece of XML and code which demonstrates the problem. I’d also suggest that you restructure your code to test for the node type being an element once, and then refactor the “handling an element” part into a separate method… where you may well want to switch on the element name and handle each kind of element in a separate method. Smaller methods are generally easier to understand, test and debug.

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

Sidebar

Related Questions

Don't want to sort the entries. using this does not preserve the order as
I don't like Jackson. I want to use ajax but with Google Gson. So
I don't want PHP errors to display /html, but I want them to display
I don't want to take the time to learn Obj-C. I've spent 7+ years
I don't currently use ajax.net though I would be open to it if it
Don't ask why, but is there any way to suppress a failed linking error?
Don't let below code scare you away . The question is really simple, only
Don't be afraid to use any technical jargon or low-level explanations for things, please.
I don't know if thats right but for some reason my stored procedure is
I don't think this should be in my view, but instead handled by the

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.