How to Decode String to Xml String in C#

How to decode string to XML string in C#

  1. HttpUtility.HtmlDecode from System.Web
  2. WebUtility.HtmlDecode from System.Net

Decoding XML String

The contents of the process-truck-response element doesn't consist of a valid XML fragment.

Unknown IN lane LANE20 for gate LBCT<argo:gate-response xmlns:argo="http://www.navis.com/argo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.navis.com/argo GateWebserviceResponse.xsd"><process-truck-response /></argo:gate-response>

You're attempting to parse that out as an XElement and it fails (and rightly so).

You should verify that you have valid XML or at least handle cases where it contains content that you're not expecting.

Decode XML returned by a webservice ( and are replaced with and >)?

You can use HttpServerUtility.HtmlDecode(encodedString) to return the decoded string.

Appropriate msdn link HtmlDecode

Convert url-like string to xml string in C#?

HttpUtility.UrlDecode(thatString)

did the job

How do I decode a base64 encoded string containing an XML document that contains characters with accents (á,é,í,ó,ú) in C#?

It's helpful to see the bytes produced by System.Convert.FromBase64String(XmlDoc).

I've done that and took a look at the word "metálicas" in your original string (this was just the first word I found with an accent). This portion of the string is converted to the byte array 6D 65 74 E1 6C 69 63 61 73.

From that byte array it's easy to see two things:

  • This is a single byte encoding
  • It is not UTF-8: In UTF-8, bytes greater than 7F never occur on their own, always in groups of 2-4.

From there I guessed it would be some form of extended ASCII, Windows-1252 seems to work. Try the following:

xmlBase64 = System.Text.Encoding.GetEncoding(1252).GetString(System.Convert.FromBase64String(XmlDoc));

How to encode/decode XML in VBA and C#

On your xmlData, have you tried as @HatSoft says, to use Server.HtmlEncode/Server.HtmlDecode? That way you could get rid of htmlentities that doesn't work in XML.

Or you could wrap your data into a CDATA-field

Decode CDATA section in C#

http://www.w3schools.com/xml/xml_cdata.asp



Related Topics



Leave a reply



Submit