Can't generate first line of XML file

G

Guest

Hi

I am generating an XML file using data in various tables in an Access DB. So
far, I can generate the "data part" of the XML without problem, but I failed
to generate the very first line in the XML file, which reads like:

<?xml version="1.0" encoding="iso-8859-1"?>

I've tried using the processing instruction (Set procInstr =
docO.createProcessingInstruction("xml", "version=""1.0""
encoding=""iso-8859-1"""), but I don't know how to add that processing
instruction to the output. addChild doesn't work, so what shall I use ?

Thanks for help
 
E

Ed Adamthwaite

Hi Balex,
Try:
"<?xml version=" & Chr(34) & "1.0" & Chr(34) _
& " encoding=" & Chr(34) & "iso-8859-1" _
& Chr(34) & "?>" & vbcrlf

HTH,
Ed.
 
G

Guest

Hi Balex

How are you creating your XML file?

Are you using the ExportXML method. This does create the first line
automatically, allthough the only options for encoding are UTF-8 or UTF-16.

If you need the encoding to be ISO-8859-1 then you could:

- Use ExportXML to create the file.
- Extract the XML as a string using the OpenTextFile method.
- Use the Replace method to replace UTF-8 with ISO-8859-1
- Send the string back to the file using the OpenAsTextStream method. This
will overwrite the original with your amended string.

Just an idea...

Cheers.

BW
 
G

Guest

I'm creating my XML file the "hard but right" way...:) using all the methods
offered by the MSXML.DOMDocument object, such as createElement, setAttribute,
createProcessingInstruction, appendChild, and save.

I have to do that, because my XML is not just the straight conversion of a
table (like it seems many of you are doing), but based on data in various
tables in different DBs, including Access and Sybase, so I have to build a
bespoke XML containing the data.

However, strange enough, I could not find the way to include the contents of
my ProcessingInstructions (which according to MS is the way to set the data
in the <?xml...?> "tag") in the resulting XML.

And it starts to look like the only way to do that if you're using Access is
to "post-process" the XML file, inserting the desired string at the beginning
of the file, which frankly is very ugly to me. I just was hoping there would
be a native method to do that within the MSXML.DOMDocument object, but I
couldn't find it, and the posts so far are not hinting to anything in that
direction either.

I found a VB.Net example that could add the equivalent of the processing
instruction at the top of the XML, it was just using the appendChild method,
but when I "translated" that to Access VBA, it always gave me an error
because the processing instruction is a completely different data type than
the element or node that is accepted by appendChild.

I'll try your last idea, using the OpenAsTextStream method. That might be
the simplest answer.

Thanks
Balex
 
G

Guest

Hi Balex

You mention that your XML is drawn from several data sources.

Are you aware that the ExportXML method isn't just about exporting the
contents of 1 table? It can, amongst several other options, export the output
from queries.

So if your data can be extracted using a SQL query then you can use :

Application.ExportXML acExportQuery, "QueryName", "Destination path/file"

Cheers.

BW
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top