If you create an HL7 MSH segment with XmlDocument, you can get a strange break line in all empty values, like in the following image.
The HL7 message will also be created with the same break line, generating an invalid HL7 message.
It’s easy to deal with it, just set PreserveWhitespace property in XmlDocument with “true”, before assigning it to the HL7 MSHSegment.
xmlDocument.PreserveWhitespace = true;
hl7msg.MSHSegment = xmlDocument;
You can get more info in https://msdn.microsoft.com/en-us/library/system.xml.xmldocument.preservewhitespace(v=vs.110).aspx.