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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:17:47+00:00 2026-05-23T01:17:47+00:00

I was having some difficulties with some text I was receiving from a Web

  • 0

I was having some difficulties with some text I was receiving from a Web Service I consume recently. The web service sends back XML, which is fine, but we’re getting ASCII control characters in the middle of some of the XML. I wanted to paste an example in this posting but being invalid characters, I can’t even paste it into this textarea.

I spent some time researching what to do in these cases and I found this informative article: http://seattlesoftware.wordpress.com/2008/09/11/hexadecimal-value-0-is-an-invalid-character/. Here is a quote from this article that is relevant:

These aren’t characters that have any
business being in XML data; they’re
illegal characters that should be
removed…

So, following the article’s advice I’ve written some code to take the raw output from this service and strip it of any character that is a control character (and that is not a space, tab, cr or lf)

Here is that code:

System.Net.WebClient client = new System.Net.WebClient();

byte[] invalidCharacters = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0xB, 
                             0xC, 0xE, 0xF, 0x10, 0x11, 0x12, 0x14, 0x15, 0x16, 
                             0x17, 0x18, 0x1A, 0x1B, 0x1E, 0x1F, 0x7F };

byte[] sanitizedResponse = (from a in client.DownloadData(url)
                            where !invalidCharacters.Contains(a)
                            select a).ToArray();

result = System.Text.UTF8Encoding.UTF8.GetString(sanitizedResponse);

This got me thinking though. If I receive double-byte characters, will I screw up any of the data I’m getting back? Is it valid for some codepages to have double-byte characters that are made up of one or two single byte ASCII control characters? The article saying that these characters have “no business” being in XML data sounds final but I want a second opinion.

Appreciate any feedback

  • 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-23T01:17:47+00:00Added an answer on May 23, 2026 at 1:17 am

    Well, the code you’ve shown is assuming UTF-8 – which would never have any of those bytes in its data (other than for those characters), due to the way it’s designed. However, I’d encourage a text-driven approach instead of this byte-driven approach – I’d probably use DownloadString instead of DownloadData (and rely on WebClient picking the right encoding) but then scrub the data with a regex before parsing it.

    I’d also contact the web service provider to explain that they’re serving duff XML…

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

Sidebar

Related Questions

I’m having some difficulties while trying to consume an unmanaged-code dll from my application
I'm having some difficulties creating a sum from values I have in a collection.
i'm trying to set up the selenium-maven-plugin and having some difficulties i hope somebody
Although there are some similar questions I’m having difficulties finding an answer on how
I am having difficulties with forms, specifically ModelMultipleChoiceField. I've pieced together this code from
We're letting users search a database from a single text input and I'm having
I'm trying to replicate some C# code in PHP5 and am having some difficulties.
I'm fairly new to Java and I've been having some difficulties with Swing. I'm
I asked a question earlier today about singletons, and I'm having some difficulties understanding
I'm having some difficulties converting this old mailer api to rails 3: content_type multipart/mixed

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.