0

I'm having some trouble loading an xml file into 'DOMDocument60'. It's a plain text file saved as XML. After the load in VBA it's missing the encoding line.

Any ideas? Many thanks in advance,

Dim MyDom As MSXML2.DOMDocument60
Set MyDom = New MSXML2.DOMDocument60

FILEL = "c:/temp/test.xml"
MyDom.Async = False
MyDom.validateOnParse = True
MyDom.Load (FILEL)

First Line

<?xml version="1.0" encoding="UTF-8"?> 

Changes to

<?xml version="1.0"?>
Gregory
  • 149
  • 2
  • 5
  • 13
  • 3
    https://stackoverflow.com/questions/541174/why-does-createprocessinginstruction-in-msxml-generate-incomplete-output or maybe https://groups.google.com/forum/#!topic/borland.public.delphi.xml/t5eMwqAa-Yo – Tim Williams Jan 15 '19 at 01:45

1 Answers1

2

This is very usual.

MSXML loads the file, uses the encoding to understand how it's encoded, then converts all encoded data to UTF-16 and removes the encoding since it's no longer representative of how the file is encoded.

If you want access to the encoding, you can read the file by just reading the text (for example, by using the ADODB stream object which allows you to specify encoding and easily outputs UTF-16 strings).

If you want to export to a specific encoding after processing, see the answer by bobince on the comment by Tim Williams.

Erik A
  • 31,639
  • 12
  • 42
  • 67