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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:27:33+00:00 2026-05-28T05:27:33+00:00

I have an XML (assuming it is valid) and I must parse it and

  • 0

I have an XML (assuming it is valid) and I must parse it and store it in a tree.

What is the best approach to parse it, without using other libraries, just basic manipulation of strings?

Keep in mind that I don’t have to validate it, just parse and memorize it into a tree.

  • 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-28T05:27:34+00:00Added an answer on May 28, 2026 at 5:27 am

    The basic structure of XML is quite simple:

    <tagname [attribute[="value"] ...]>content</tagname>
    

    where the content may contain both normal text and more XML structures, or the special form

    <tagname [attribute[="value"] ...]/>
    

    which is equivalent to

    <tagname [attribute[="value"] ...]></tagname>
    

    that is,. empty content.

    So if you don’t need to interpret a DTD or do other fancy things, you can do the following:

    1. Check that the first non-whitespace character is <. If not, you don’t have XML and can just give an error and exit.

    2. Now follows the tag name, until the first whitespace, or the / or the > character. Store that.

    3. If the next non-whitespace character is /, check that it is followed by >. If so, you’ve finished parsing and can return your result. Otherwise, you’ve got malformed XML, and can exit with an error.

    4. If the character is >, then you’ve found the end of the begin tag. Now follows the content. Continue at step 6.

    5. Otherwise what follows is an argument. Parse that, store the result, and continue at step 3.

    6. Read the content until you find a < character.

    7. If that character is followed by /, it’s the end tag. Check that it is followed by the tag name and >, and if yes, return the result. Otherwise, throw an error.

    8. If you get here, you’ve found the beginning of a nested XML. Parse that with this algorithm, and then continue at 6.

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

Sidebar

Related Questions

Assuming you have the following XML: <?xml version=1.0 encoding=utf-8?> <content> <info> <media> <image> <info>
Assuming you have two lists defined in an xml schema, call them A and
I have xml files I want to read in and store in the database.
Assuming I have a SQL Server 2005 table with an xml column containing the
Assuming I have a .properties file and hibernate.cfg.xml in a standard maven web application
Assuming I have a XML like so: <a> <b> <i>data</i> <ii>data</ii> <iii>data</iii> </b> <b>
Assuming I have just used an XPath query to get the 5th instance of
Assuming I have a simple XML with only one item... <myXML> <valuesItem name =
Assuming I have a xdocument called xd, with the following xml already created. <Alert>
I have xml where some of the element values are unicode characters. Is it

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.