364,085 Members | 5253 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

write XML with line feeds?

Arthur Hoornweg
P: n/a
Arthur Hoornweg
Hello World,

any idea how I can convince MSXML.IXMLDOMDocument to
save the XML files using CR/LF?

I need to manually edit the XML files and it's
awkward if everything is in one huge line.




--
Arthur Hoornweg
(please remove the ".net" from my e-mail address)

Nov 12 '05 #1
Share this Question
Share on Google+
4 Replies


NaraendiraKumar R. R.
P: n/a
NaraendiraKumar R. R.
Looks like you are using the MSXML 3.0 or 4.0 via COM?

If you are doing this from a .NET environment, you can automate the
indentation by passing the string through an XML Writer.

If you just need it for viewing purposes, you could use some XML editor.
VS.NET does a decent job. Also XML Spy & Cooktop.

-Naraen

---
"Arthur Hoornweg" <arthur.hoornweg@wanadoo.nl.net> wrote in message
news:OMYGE1vGEHA.1228@TK2MSFTNGP11.phx.gbl...[color=blue]
> Hello World,
>
> any idea how I can convince MSXML.IXMLDOMDocument to
> save the XML files using CR/LF?
>
> I need to manually edit the XML files and it's
> awkward if everything is in one huge line.
>
>
>
>
> --
> Arthur Hoornweg
> (please remove the ".net" from my e-mail address)
>[/color]


Nov 12 '05 #2

Arthur Hoornweg
P: n/a
Arthur Hoornweg
NaraendiraKumar R. R. wrote:
[color=blue]
> Looks like you are using the MSXML 3.0 or 4.0 via COM?[/color]

Yes.
[color=blue]
>
> If you are doing this from a .NET environment, you can automate the
> indentation by passing the string through an XML Writer.
>
> If you just need it for viewing purposes, you could use some XML editor.
> VS.NET does a decent job. Also XML Spy & Cooktop.
>[/color]


Just a second. So something as basic as "human legible XML" is
not possible with MSXML 3.0?

Any other incarnations of MSXML that do better?


--
Arthur Hoornweg
(please remove the ".net" from my e-mail address)
Nov 12 '05 #3

Martin Honnen
P: n/a
Martin Honnen


Arthur Hoornweg wrote:
[color=blue]
> NaraendiraKumar R. R. wrote:
>[color=green]
>> Looks like you are using the MSXML 3.0 or 4.0 via COM?[/color]
>
>
> Yes.
>[color=green]
>>
>> If you are doing this from a .NET environment, you can automate the
>> indentation by passing the string through an XML Writer.
>>
>> If you just need it for viewing purposes, you could use some XML editor.
>> VS.NET does a decent job. Also XML Spy & Cooktop.
>>[/color]
>
>
> Just a second. So something as basic as "human legible XML" is
> not possible with MSXML 3.0?
>
> Any other incarnations of MSXML that do better?[/color]

It is possible, for instance using XSLT, here is a JScript/WSH example
using Msxml2.DOMDocument.4.0 to first create a document in memory, then
a simple XSLT stylesheet is used to "pretty-print" that document and
then it is saved

var xmlDocument = new ActiveXObject('Msxml2.DOMDocument.4.0');
xmlDocument.appendChild(xmlDocument.createElement( 'gods'));
var element = xmlDocument.createElement('god');
element.setAttribute('name', 'Kibo');
xmlDocument.documentElement.appendChild(element);
element = xmlDocument.createElement('god');
element.setAttribute('name', 'Xibo');
xmlDocument.documentElement.appendChild(element);
WScript.Echo(xmlDocument.xml);

var indentedDocument = new ActiveXObject('Msxml2.DOMDocument.4.0');
var xslIndenter = new ActiveXObject('Msxml2.DOMDocument.4.0');
xslIndenter.async = false;
xslIndenter.load('test20040406Xsl.xml');

xmlDocument.transformNodeToObject(xslIndenter, indentedDocument);

WScript.Echo(indentedDocument.xml);

indentedDocument.save('test20040406.xml');

Output shows the original document first and then the indented one

<gods><god name="Kibo"/><god name="Xibo"/></gods>

<?xml version="1.0"?>
<gods>
<god name="Kibo"></god>
<god name="Xibo"></god>
</gods>

The simple XSLT stylesheet is

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes" encoding="UTF-8" />

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #4

NaraendiraKumar R.R.
P: n/a
NaraendiraKumar R.R.
Without .NET, the method Martin mentioned is the way to go.

-Naraen

----
"Martin Honnen" <mahotrash@yahoo.de> wrote in message
news:O1eqEe8GEHA.1228@TK2MSFTNGP11.phx.gbl...[color=blue]
>
>
> Arthur Hoornweg wrote:
>[color=green]
> > NaraendiraKumar R. R. wrote:
> >[color=darkred]
> >> Looks like you are using the MSXML 3.0 or 4.0 via COM?[/color]
> >
> >
> > Yes.
> >[color=darkred]
> >>
> >> If you are doing this from a .NET environment, you can automate the
> >> indentation by passing the string through an XML Writer.
> >>
> >> If you just need it for viewing purposes, you could use some XML[/color][/color][/color]
editor.[color=blue][color=green][color=darkred]
> >> VS.NET does a decent job. Also XML Spy & Cooktop.
> >>[/color]
> >
> >
> > Just a second. So something as basic as "human legible XML" is
> > not possible with MSXML 3.0?
> >
> > Any other incarnations of MSXML that do better?[/color]
>
> It is possible, for instance using XSLT, here is a JScript/WSH example
> using Msxml2.DOMDocument.4.0 to first create a document in memory, then
> a simple XSLT stylesheet is used to "pretty-print" that document and
> then it is saved
>
> var xmlDocument = new ActiveXObject('Msxml2.DOMDocument.4.0');
> xmlDocument.appendChild(xmlDocument.createElement( 'gods'));
> var element = xmlDocument.createElement('god');
> element.setAttribute('name', 'Kibo');
> xmlDocument.documentElement.appendChild(element);
> element = xmlDocument.createElement('god');
> element.setAttribute('name', 'Xibo');
> xmlDocument.documentElement.appendChild(element);
> WScript.Echo(xmlDocument.xml);
>
> var indentedDocument = new ActiveXObject('Msxml2.DOMDocument.4.0');
> var xslIndenter = new ActiveXObject('Msxml2.DOMDocument.4.0');
> xslIndenter.async = false;
> xslIndenter.load('test20040406Xsl.xml');
>
> xmlDocument.transformNodeToObject(xslIndenter, indentedDocument);
>
> WScript.Echo(indentedDocument.xml);
>
> indentedDocument.save('test20040406.xml');
>
> Output shows the original document first and then the indented one
>
> <gods><god name="Kibo"/><god name="Xibo"/></gods>
>
> <?xml version="1.0"?>
> <gods>
> <god name="Kibo"></god>
> <god name="Xibo"></god>
> </gods>
>
> The simple XSLT stylesheet is
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <xsl:output method="xml" indent="yes" encoding="UTF-8" />
>
> <xsl:template match="@* | node()">
> <xsl:copy>
> <xsl:apply-templates select="@* | node()" />
> </xsl:copy>
> </xsl:template>
>
> </xsl:stylesheet>
>
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/
>[/color]


Nov 12 '05 #5

Post your reply

Help answer this question



Didn't find the answer to your .NET Framework question?

You can also browse similar questions: .NET Framework