I created XML Document and saved this document as
XmlDocument xmlDoc = new XmlDocument();
XmlDeclaration dec = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
xmlDoc.AppendChild(dec);
XmlTextWriter writer = new XmlTextWriter(fullPath,Encoding.UTF8);
writer.Formatting = Formatting.Indented;
xMLDoc.Save(writer);
writer.Flush();
And then I have encoded this document using Base64 Encoder
The Decoder could not parse XML file. I created the decoder myself and got this result
?<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<ClinicalDocument
xmlns=\"urn:hl7-org:v3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
classCode=\"DOCCLIN\" moodCode=\"EVN\" schemaLocation=\"urn:hl7-org:v3
CDA.xsd\">\r\n <typeId extension=\"POCD_HD000040\" root=\"2.16.840.1.113883.1.3
\" />\r\n
Please help me to resolve the issue. How I have to save the XML file to avoid the issues? Or How I have to encode to Base 64 to resolve the issue? I am using base64 encoder to encode xml file. I am requesting document. it is required to use base64 encoder. I decoded myself to check where is the problem. The decoder is Java . They can not parse the xml file I believe because ?< in front of the document.
To decode with base64 you need to use the --decode flag. With encoded string, you can pipe an echo command into base64 as you did to encode it. Using the example encoding shown above, let's decode it back into its original form. Provided your encoding was not corrupted the output should be your original string.
Base64 is an encoding and decoding technique used to convert binary data to an American Standard for Information Interchange (ASCII) text format, and vice versa.
A. Base64 Algorithm The Base64 algorithm is one of the algorithms for Encoding and Decoding an object into ASCII format, which is meant for the base number 64 or one of the methods used to encode the binary data[11], [12].
It depends on how you're encoding it, but you should use UTF-8 since the document is declared as such. Here are examples for encoding and decoding:
See Jon Skeet's answer here:
C# base64 encoding/decoding with serialization of objects issue
To encode:
public string EncodeStringToBase64(string stringToEncode)
{
return Convert.ToBase64String(Encoding.UTF8.GetBytes(stringToEncode));
}
To decode:
public string DecodeStringFromBase64(string stringToDecode)
{
return Encoding.UTF8.GetString(Convert.FromBase64String(stringToDecode));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With