Discussion:
MSXML writing xml files idented?
(too old to reply)
lallous
2006-01-30 12:08:08 UTC
Permalink
Hello

When I save an XML document, through the MSXML interface, the output file is
not idented and all the tags are written next to each other.

Is there is a flag to tell the writer to save in an idented format?

--
Elias
Arkady Frenkel
2006-01-30 12:26:21 UTC
Permalink
That only viewers show it intended, XML have to be without spaces for
intercomputer communications
Arkady
Post by lallous
Hello
When I save an XML document, through the MSXML interface, the output file
is not idented and all the tags are written next to each other.
Is there is a flag to tell the writer to save in an idented format?
--
Elias
Alex Blekhman
2006-01-30 12:49:38 UTC
Permalink
Post by lallous
Hello
When I save an XML document, through the MSXML interface,
the output file is not idented and all the tags are
written next to each other.
Is there is a flag to tell the writer to save in an
idented format?
As Arkady already answered, indentation is only for human
readers. However, if you really need itm then use
MXXMLWriter object for output. Set indent property to true.
Martin Honnen
2006-01-30 13:20:03 UTC
Permalink
Post by lallous
When I save an XML document, through the MSXML interface, the output file is
not idented and all the tags are written next to each other.
Is there is a flag to tell the writer to save in an idented format?
There is a setting
preserveWhiteSpace
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/824383e0-8409-4e13-bc93-fb0191343402.asp>
you can set to true on the DOMDocument object before loading XML (with
the load method from a file or URL or with the loadXML method from a
string), that way indentation is being preserved when you save back with
the save method.

If you build the complete DOMDocument with e.g. createElement,
appendChild with the DOM then however the save method alone does not
help to get indentation. Others however have already pointed you to
MXXMLWriter. Another way could be to run the the created DOM document
through an XSLT stylesheet that does the indentation.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Tony Proctor
2006-01-31 09:31:57 UTC
Permalink
If you're using any XSLT to generate your final XML, try putting the
following statement in your XSL file:

<xsl:output indent="yes"/>


Tony Proctor
Post by lallous
Hello
When I save an XML document, through the MSXML interface, the output file is
not idented and all the tags are written next to each other.
Is there is a flag to tell the writer to save in an idented format?
--
Elias
G***@gmail.com
2006-02-11 16:55:31 UTC
Permalink
This is cut & paste from the MSXML4 SDK documentation...which you can
find on the MS website...

'Create a DOMDocument object.
Dim xmlDoc As New DOMDocument40
'Create the reader.
Dim rdr As New SAXXMLReader40
'Create the writer.
Dim wrt As New MXXMLWriter40

'Load the DOM document.
xmlDoc.async = False
xmlDoc.resolveExternals = False
xmlDoc.Load ("books.xml")

'Set properties on the XML writer.
wrt.byteOrderMark = True
wrt.omitXMLDeclaration = False
wrt.indent = True

'Set the XML writer to the SAX content handler.
Set rdr.contentHandler = wrt
Set rdr.dtdHandler = wrt
Set rdr.errorHandler = wrt
rdr.putProperty "http://xml.org/sax/properties/lexical-handler",
wrt
rdr.putProperty
"http://xml.org/sax/properties/declaration-handler", wrt

'Parse the DOMDocument object.
rdr.parse xmlDoc

'Show the results in the text box.
msgbox wrt.output

you might have to fuss with the .byteOrderMark and .omitXMLDeclaration
to get what you want.

Loading...