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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:25:39+00:00 2026-05-22T12:25:39+00:00

I got an XML file from 3rd party that I must import in my

  • 0

I got an XML file from 3rd party that I must import in my app, and XML had elements with unescaped & in inner text, and they don’t wont to fix that ! So my question is what is the best way to deal with this problem ?

This XML is pretty big and that fix has to be fast, my first solution is just replace & character with ampersand but really I don’t like this “solution” for obvious reasons. I don’t know how to use XmlStringReader with such XML because is throws exception on such lines, so I can’t use HtmlEncode on inner text. I tried to set XmlTextReader Settings.CheckCharacters to false but no result.

Here is the sample, & is in element, and in that field can be anything that can be in some company name, so my replace fix maybe don’t work for some other company name, I would like to use HtmlEncode somehow, but only on inner text of course.

<komitent ID="001398">
  <sifra>001398</sifra>
  <redni_broj>001398</redni_broj>
  <naziv>LJUBICA & ŽARKO</naziv>
  <adresa1>Odvrtnica 27</adresa1>
  <adresa2></adresa2>
  <drzava>HRVATSKA</drzava>
  <grad>Zagreb</grad>
</komitent>
  • 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-22T12:25:40+00:00Added an answer on May 22, 2026 at 12:25 pm

    The key message below is that unless you know the exact format of the input file, and have guarantees that any deviation from XML is consistent, you can’t programmatically fix without risking that your fixes will be incorrect.

    Fixing it by replacing & with &amp; is an acceptable solution if and only if:

    1. There is no acceptable well-formed source of these data.

      • As @Darin Dimitrov comments, try to find a better provider, or get this provider to fix it.
      • JSON (for example) is preferable to poorly formed XML, even if you aren’t using javascript.
    2. This is a one off (or at least extremely infrequent) import.

      • If you have to fetch this in at runtime, then this solution will not work.
    3. You can keep iterating through, devising new fixes for it, adding a solution to each problem as you come across it.

      • You will probably find that once you have “fixed” it by escaping & characters, there will be other errors.
    4. You have the resources to manually check the integrity of the “fixed” data.

      • The errors you “fix” may be more subtle than you realise.
    5. There are no correctly formatted entities in the document –

      • Simply replacing & with &amp; will erroneously change &quot; to &amp;quot;. You may be able to get around this, but don’t be naive about how tricky it might be (entities may be defined in a DTD, may refer to a unicode code-point …)

      • If it is a particular element that misbehaves, you could consider wrapping the content of the element with <![CDATA ]]>, but that still relies on you being able to find the start and end tags reliably.

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

Sidebar

Related Questions

I need to parse a XML file which I get from third party to
I've got three questions here. First, does pom.xml of maven have any difference from
I am trying to read in an XML file and compare it to fields
I've implemented caching on a file (XML) which gets sent to the graphs controls
I'm trying to display the biggest image url returned from an xml result. So
I've got a drupal site that gets low traffic, but has tons of new
Has anyone got EclipseLink MOXy (I'm using eclipselink 2.1.0) to work with Java 5?
Im trying to create a RSS feed reader for a project that I working
I've got a number of paths like in memory (contained in an ArrayList): C:\Program
I am trying to build out the preferences for my application and I was

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.