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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:28:48+00:00 2026-05-26T03:28:48+00:00

UPDATE: The invalid characters are actually in the attributes instead of the elements, this

  • 0

UPDATE: The invalid characters are actually in the attributes instead of the elements, this will prevent me from using the CDATA solution as suggested below.

In my application I receive the following XML as a string. There are a two problems with this why this isn’t accepted as valid XML.
Hope anyone has a solution for fixing these bug gracefully.

  1. There are ASCII characters in the XML that aren’t allowed. Not only the one displayed in the example but I would like to replace all the ASCII code with their corresponding characters.

  2. Within an element the ‘<‘ exists – I would like to remove all these entire ‘inner elements’ (<L CODE=&#034;C01&#034;>WWW.cars.com</L>) from the XML.

<?xml version="1.0" encoding="ISO-8859-1"?>
<cars>
  <car model="ford" description="Argentini&#235; love this"/>
  <car model="kia" description="a small family car"/>
  <car model="opel" description="great car <L CODE=&#034;C01&#034;>WWW.cars.com</L>"/>
</cars>
  • 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-26T03:28:49+00:00Added an answer on May 26, 2026 at 3:28 am

    For a quick fix, you could load this not-XML into a string, and add [CDATA][1] markers inside any XML tags that you know usually tend to contain invalid data. For example, if you only ever see bad data inside <description> tags, you could do:

    var soCalledXml = ...;
    var xml = soCalledXml
        .Replace("<description>", "<description><![CDATA[")
        .Replace("</description>", "]]></description>");
    

    This would turn the tag into this:

    <description><![CDATA[great car <L CODE=&#034;C01&#034;>WWW.cars.com</L>]]></description>
    

    which you could then process successfully — it would be a <description> tag that contains the simple string great car <L CODE=&#034;C01&#034;>WWW.cars.com</L>.

    If the <description> tag could ever have any attributes, then this kind of string replacement would be fraught with problems. But if you can count on the open tag to always be exactly the string <description> with no attributes and no extra whitespace inside the tag, and if you can count on the close tag to always be </description> with no whitespace before the >, then this should get you by until you can convince whoever is producing your crap input that they need to produce well-formed XML.


    Update

    Since the malformed data is inside an attribute, CDATA won’t work. But you could use a regular expression to find everything inside those quote characters, and then do string manipulation to properly escape the <s and >s. They’re at least escaping embedded quotes, so a regex to go from " to " would work.

    Keep in mind that it’s generally a bad idea to use regexes on XML. Of course, what you’re getting isn’t actually XML, but it’s still hard to get right for all the same reasons. So expect this to be brittle — it’ll work for your sample input, but it may break when they send you the next file, especially if they don’t escape & properly. Your best bet is still to convince them to give you well-formed XML.

    using System.Text.RegularExpressions;
    
    var soCalledXml = ...;
    var xml = Regex.Replace(soCalledXml, "description=\"[^\"]*\"",
        match => match.Value.Replace("<", "&lt;").Replace(">", "&gt;"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're parsing an XML document using JAXB and get this error: [org.xml.sax.SAXParseException: Invalid byte
Update: Check out this follow-up question: Gem Update on Windows - is it broken?
UPDATE: Focus your answers on hardware solutions please. What hardware/tools/add-in are you using to
Update: Now that it's 2016 I'd use PowerShell for this unless there's a really
Update: Please read this question in the context of design principles, elegance, expression of
I'm getting an Invalid Character Constant under the 'D just after UPDATE. Any Ideas?
I have to read the below SQL statement from one properties. update scoreconfig set
Update: Apparently these are control characters, not Unicode characters. I'm trying to parse an
My code, when compiled, returns the error invalid conversion from ‘char*’ to ‘char’ ,
Update: Solved, with code I got it working, see my answer below for 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.