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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:08:16+00:00 2026-05-30T13:08:16+00:00

DISCLAIMER: Yes, I know the solution is not optimal, but it is what it

  • 0

DISCLAIMER: Yes, I know the solution is not optimal, but it is what it is.

We are creating a large XML file and then serving it via a WCF service. The consumer is a vendor that has a mobile gateway. They take the large file and chop it up for mobile calls.

The actual creation bits use the Microsoft XML objects (XmlDocument, XmlElement, XmlTextNode, etc.) and then saved to the file system. The service pulls the file and reconstitutes it as an XML document and serves it.

[OperationContract]
[Description("Gets all products for SnP and Systems.")]
[WebGet(UriTemplate = "shop/products/all?appId={appId}")]
XmlElement GetAllProductsAsXmlDocument(string appId);

When I produce a file, I end up with a file that looks something like this:

<content>&lt;b&gt;Intel® Core™ Duo &amp; 2 GB RAM&lt;/b&gt;</content>

Which, in a browser as HTML, would look like this <b>Intel® Core™ Duo & 2 GB RAM</b>.

The vendor has asked to have the text in the XML document to look like this:

<content>&lt;b&gt;Intel&reg; Core&trade; Duo &amp; 2 GB RAM&lt;/b&gt;</content>

If this were a string, rather than text in an XML node, I could easily do this:

string hackedString = HttpUtility.HtmlEncode(nonHackedTextFromXmlNode);

But encoding and then slapping into the XmlDocument as a TextNode yields:

<content>&lt;b&gt;Intel® Core™ Duo &amp; 2 GB RAM&lt;/b&gt;</content>

So the Microsoft Xml recognizes certain escaped HTML sequences and turns them into the version found in their specification of XML. Dinking around with manually encoding, I can aslo end up with &amp;amp; and &amp;#174; (a messed up ®, as 174 decimal == ®), but if the symbol is recognized going into the XML document, it looks like the above when the escaped versions are loaded.

The question is this Is there some unique type of encoding or setting or “other” that can be used with an .NET XmlDocument to produce nodes that automagically respect HTML encoding rules?

If it can’t be done, that is fine. I have already suggested two possibilities:

  1. Create CDATA nodes instead of standard text nodes, so the encoding is not altered
  2. Transform the characters after the file is saved and serve it as a string, not an XmlDocument, in the WCF service.
  3. Have the vendor translate the data to HTML escaped strings

Thoughts?

ADDITIONAL INFO:
Per suggestion, added the HTML DTD:

string dtdLink = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"; 
string dtdDef = "-//W3C//DTD XHTML 1.0 Transitional//EN"
XmlDocumentType docType = htmlDoc.CreateDocumentType("html", dtdDef, dtdLink, null);
htmlDoc.AppendChild(docType);

Still adds extra &amp; to the output. May try the other HTML DTDs, but I am soon to run out of time. Thanks.

  • 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-30T13:08:17+00:00Added an answer on May 30, 2026 at 1:08 pm

    The issue, overall, is Microsoft corrects a lot of things. CDATA avoids some of the correction. Note that this correction is proper and there would be no issue if the vendor had their parser set up for UTF-8. Sometimes you just have to say “it is what it is”.

    The solution employed was add a scrubbing “filter” to the end of the processing pipeline. Nasty solution, since it did not properly solve the problem and the client (internal) now wants the filter on all services.

    The proper solution would have been to have the vendor respect UTF-8 so we did not have to scrub perfectly valid characters. Unfortunately, as with many projects, time was more important than quality.

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

Sidebar

Related Questions

Disclaimer: This is not actually a programming question, but I feel the audience on
Disclaimer: This is for a homework assignment, but the question is not regarding the
Disclaimer This is not strictly a programming question, but most programmers soon or later
Disclaimer : I have seen the exact questions, but have not seen any answers
Disclaimer Yes, I know: don't use PASSWORD(password) to encrypt passwords . I don't want
Disclaimer: Yes, I am forced to support PHP 4.3.0. I know it's dead. No
Disclaimer: I understand the question is very basic, but I could not find the
Disclaimer: This is for a programming class, but it is not the answer or
Disclaimer Yes, I am fully aware that what I am asking about is totally
Disclaimer: the following is a sin against XML. That's why I'm trying to change

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.