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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:29:31+00:00 2026-05-13T14:29:31+00:00

I get the XML from a web service in the format below and I

  • 0

I get the XML from a web service in the format below and I want to clean it up (remove the extra “\” and “\n” characters) before working with it. I am currently using the regular expression below to match. However only the “\n” characters are cleaned up, while the “\” characters which are in between equal and double quotation marks persist.

What do you advise me to do?

private string ValidateXml(string dirtyXml) {
    Regex regex = new Regex(@"[\\\][\n]");
    var cleanXml = regex.Replace(dirtyXml, "");
    return cleanXml;
}

"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<ISBNdb server_time=\"2010-01-28T11:31:08Z\">\n<BookList total_results=\"1\" page_size=\"10\" page_number=\"1\" shown_results=\"1\">\n<BookData book_id=\"quantitative_techniques\" isbn=\"0826458548\" isbn13=\"9780826458544\">\n<Title>Quantitative techniques</Title>\n<TitleLong></TitleLong>\n<AuthorsText>Terry Lucey</AuthorsText>\n<PublisherText publisher_id=\"continuum\">London : Continuum, 2002.</PublisherText>\n</BookData>\n</BookList>\n</ISBNdb>\n"
  • 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-13T14:29:32+00:00Added an answer on May 13, 2026 at 2:29 pm

    The question still isn’t clear: if you write the XML string (before you try to clean it) to the console, do you see exactly what you posted above, with all those \" and \n sequences? Does the displayed string start and end with a quotation mark? If so, you probably want to remove the opening and closing quotation marks and all the backslashes, and if any backslash is followed by an ‘n’, you want to remove that as well. Here’s some code to demonstrate:

    static void Main(string[] args)
    {
      string dirtyXml = @"""<?xml version=\""1.0\"" encoding=\""UTF-8\""?>\n\n<ISBNdb server_time=\""2010-01-28T11:31:08Z\"">\n<BookList total_results=\""1\"" page_size=\""10\"" page_number=\""1\"" shown_results=\""1\"">\n<BookData book_id=\""quantitative_techniques\"" isbn=\""0826458548\"" isbn13=\""9780826458544\"">\n<Title>Quantitative techniques</Title>\n<TitleLong></TitleLong>\n<AuthorsText>Terry Lucey</AuthorsText>\n<PublisherText publisher_id=\""continuum\"">London : Continuum, 2002.</PublisherText>\n</BookData>\n</BookList>\n</ISBNdb>\n""";
      Console.WriteLine(dirtyXml);
      Console.WriteLine();
      Console.WriteLine(Regex.Replace(dirtyXml, @"^""|""$|\\n?", ""));
    }
    

    output:

    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<ISBNdb server_time=\"2010-01-28T11:31:08Z\">\n<BookList total_results=\"1\" page_size=\"10\" page_number=\"1\" shown_results=\"1\">\n<BookData book_id=\"quantitative_techniques\" isbn=\"0826458548\" isbn13=\"9780826458544\">\n<Title>Quantitative techniques</Title>\n<TitleLong></TitleLong>\n<AuthorsText>Terry Lucey</AuthorsText>\n<PublisherText publisher_id=\"continuum\">London : Continuum, 2002.</PublisherText>\n</BookData>\n</BookList>\n</ISBNdb>\n"

    <?xml version="1.0" encoding="UTF-8"?><ISBNdb server_time="2010-01-28T11:31:08Z"><BookList total_results="1" page_size="10" page_number="1" shown_results="1"><BookData book_id="quantitative_techniques" isbn="0826458548" isbn13="9780826458544"><Title>Quantitative techniques</Title><TitleLong></TitleLong><AuthorsText>Terry Lucey</AuthorsText><PublisherText publisher_id="continuum">London : Continuum, 2002.</PublisherText></BookData></BookList></ISBNdb>

    Does this accurately reflect what you’re starting with and what you want to end up with?

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

Sidebar

Related Questions

I am trying to get the raw XML response from a web service, instead
What I want: get a xml from the AppData to use What I code
I'm working with XML data from an application where we get XML like this:
Web app. Get data from services in json & xml formats. And from internal
I am getting responses from two different web services in XML format. Both web
I need to get Json data from a C# web service. I know there
I've managed to parse xml responses from a SOAP web service when I receive
I have a few windwos services. They get xml column from Sql server manipulate
I am calling oracle package, to get xml file from the package into oracleDataReader.
I get an XML string from a certain source. I create a DOMDocument object

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.