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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:52:34+00:00 2026-05-11T18:52:34+00:00

I have a file, which is in XML format (consists just of root start

  • 0

I have a file, which is in XML format (consists just of root start and end tags, and children of the root). The text elements of the children contain the ampersand symbol &. In XML it is not allowed to have this symbol in order the document to be valid, and when I tried to process the file using the DOM API in Java and an XML parser, I obtained parsing errors. Therefore, I have replaced & with &, and I processed the file successfully: I had to extract the values of the text elements in different plain text files.

When I opened these newly created text files, I expected to see &, but there was & instead. Why is this? I have stored the text in text files without any extension (my original file with the XML format also did not have .xml extension), and I do have just & in the text of the new file, no matter how I open the file: as txt or as xml file (these are some of the options in my XML editor). What happens exactly? Does Java (?) convert & to & automatically? Or there is some default encoding? Well, & stands for &, and I suppose there is some “invisible” automatic conversion, but I am confused when and how this happens. Here are examples of my original file and the extracted file which I receive after I processed the original file with Java:

This is my “negative.review” file in XML format:

<review>
<review_text>
I will not wear it as it is too big &amp; looks funny on me. 
</review_text>
</review>

This is my extracted file “negative_1”:

I will not wear it as it is too big & looks funny on me. 

For me it is important to have the original data as it is (without doing any conversions/replacements), so I thought that I have to process the extracted file “negative_1” converting back &amp; to &. As you see, it seems I don’t have to do this. But I don’t understand why :(.

Thank you 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-11T18:52:35+00:00Added an answer on May 11, 2026 at 6:52 pm

    The reason is simple: The XML file really contains an "&" character.

    It is just represented differently (i.e. it is “escaped”), because a real "&" on it’s own breaks XML files, as you’ve seen. Read the relevant section in the XML 1.0 spec: “2.4 Character Data and Markup”. It’s just a few lines, but it explains the issue quite well.

    XML is a representation of data (!). Don’t think of it as a text file. Example:

    You want to store the string “17 < 20” in an XML file. Initially, you can’t, since the “<” is reserved as the opening tag bracket. So this would be invalid:

    <xml>17 < 20</xml>
    

    Solution: You employ character escaping on the special/reserved character, just for the means of retaining the validity of the file:

    <xml>17 &lt; 20</xml>
    

    For all practical purposes the above snippet contains the following data (in JSON representation this time):

    {
      "xml": "17 < 20"
    }
    

    This is why you see the real "&" in your post-processing. It had been escaped in just the same way, but it’s meaning stayed the same all the time.

    The above example also explains why the "&" must be treated specially: It is itself part of the XML escaping mechanism. It marks the start of an escape sequence, like in "&lt;". Therefore it must be escaped itself (with "&amp;", like you’ve done).

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

Sidebar

Related Questions

I have a custom XML file format which can contain blocks of code within
I have an XML file which is in the following format: <root> <category> <doctype>
I have an XML file which I'd like to parse into a non-XML (text)
I have an xml file which is in this format <rundate> <rundateItem> <LeaveCreditingMonth>2</LeaveCreditingMonth> <LeaveCreditingYear>2010</LeaveCreditingYear>
I have a file which is an XML representation of some data that is
Good morning. I have an XML file which contains lists of warning and errors
We have a PageRoles xml file which contains the page path and the user
i have a log file which contains hundreds/thousands of seperate XML messages and need
I have an xml file from which I am extracting html using LINQ to
I have an XML file, which I open in F# like this: let Bookmarks(xmlFile:string)

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.