How to decode string to XML string in C#
HttpUtility.HtmlDecode
fromSystem.Web
WebUtility.HtmlDecode
fromSystem.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
How to Access Ssis Package Variables Inside Script Component
Generics: Casting and Value Types, Why Is This Illegal
Detect If Geolocation Is in Complex Polygon or Not
C# Dll Cannot Affect Value of a Number Passed by Reference from a Vb6 Application
Entity Framework. Delete All Rows in Table
Event Signature in .Net -- Using a Strong Typed 'Sender'
Is Async/Await Suitable for Methods That Are Both Io and CPU Bound
How to List All Sub Directories in a Directory
Efficient Cartesian Product Algorithm
How to Take the Cartesian Join of Two Lists in C#
Hook on Default "Paste" Event of Winforms Textbox Control
Caliburn.Micro Serialization Issue When Implementing Propertychangedbase
C# Datagridview Checkbox Checked Event
Auto Versioning in Visual Studio 2017 (.Net Core)