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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:50:30+00:00 2026-06-08T18:50:30+00:00

I am getting a string of ‘xml’ that contains some content that is unescaped.

  • 0

I am getting a string of ‘xml’ that contains some content that is unescaped. Here is a trivial example:

<link text="This is some text with "potentially" some quoted text in it." linktype="external" anchor="" target="" />

The problem I have is when you try to convert the above as a string using XmlDocument.LoadXml(), LoadXml() throws an exception because of the lack of escaping on the inner quotes for the content held by attribute ‘text’. Is there a relatively painless way to escape the content specifically? Or am I just going to have to parse it/escape it/rebuild it myself?

i’m not generating this text, i just get it from another process in a string like this:

"<link text="This is some text with "potentially" some quoted text in it." linktype="external" anchor="" target="" />"
  • 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-06-08T18:50:31+00:00Added an answer on June 8, 2026 at 6:50 pm

    You need to use the html character encoding where " is &quot;

    But since your input is a malformed xml text you have to find a way to parse that text and replace the quotes with their encoded translation. Maybe some regex parsing..

    Please consider this just a creative way to make the job. I know it’s dirty but it will work in most cases:

     private static string XmlEncodeQuotes(string target) {
    
            string result = string.Empty;
            for (int i = 0; i < target.Length; i++)
            {
                if (target[i] == '"')
                {
                    if (target[i - 1] != '=')
                        if (!Regex.IsMatch(target.Substring(i), @"^""\s[a-zA-Z]+="""))
                        {
                            result += "&quot;";
                            continue;
                        }
                }
                result += target[i];
            }
            return result;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting a string from a database that is in xml format and
I'm getting a string value back from an external application that is supposed to
I am getting string objects instead of Person objects in my JSTL. Here is
In my android app, I am getting the String from an Edit Text and
Im getting a string (simplified) from the backend that should be : { menu:
I am getting a string hash like this: string content = a very long
I have a WPF Application in which I am getting string someone = TextBox.text;
I am getting a string like this: var json = title: abc, link: http://google.com,
I am getting this string via a message broker (Stomp): João and that's how
im having trouble getting a string (containing a URL) from one activity to another.

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.