title: VB6 MSXML2 DOMDocument .xml Property appends NewLine character
body: <p>I have a legacy VB 6 application to maintain which uses msxml4.dll.</p>
  
  <p>It uses the .loadXML Method of MSXML2.DOMDocument to create from xml strings and then uses the .xml Property to output strings of xml:</p>
  
  <pre><code>Dim doc As MSXML2.DOMDocument
  Set doc = CreateObject("MSXML2.DOMDocument.4.0")
  Call doc.loadXML("&lt;doc/&gt;")
  
  ' ... manipulation of doc ...
  
  Dim xml As String
  xml = doc.xml
  </code></pre>
  
  <p>I have discovered an issue with the .xml Property. When using the above code the string xml has a NewLine at the end:</p>
  
  <p><img src="https://i.stack.imgur.com/miFsL.png" alt="enter image description here"></p>
  
  <p>How can I stop this from happening?</p>
  
  <p>If it can't be stopped (i.e. if it's a bug in MSXML or by design) then how can I remove it in VB 6? <code>Trim(xml)</code> doesn't work</p>
  
  <p><strong>EDIT</strong> I have updated the question as it it the .xml Property not the .loadXML Method which appears to be at fault. If I select the doc as an Element:</p>
  
  <pre><code>Dim elm As MSXML2.IXMLDOMElement
  Set elm = doc.selectSingleNode("doc")
  xml = elm.xml
  </code></pre>
  
  <p>then the .xml Property acts as expected with no added NewLine character, so it appears it is specific to the DOMDocument.xml Property.</p>
  
  <p><strong>EDIT 2:</strong> Following SpectralGhost's answer, here is what I ended up using:</p>
  
  <pre><code>If Right(xml, Len(vbNewLine)) = vbNewLine Then
      xml = Left(xml, Len(xml) - Len(vbNewLine))
  End If
  </code></pre>
  
  <p>I use vbNewLine to avoid platform specific issues.</p>