write XML with line feeds?

閲覧: 4 回
最初の未読メッセージにスキップ

Arthur Hoornweg

未読、
2004/04/05 12:00:572004/04/05
To:
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)

NaraendiraKumar R. R.

未読、
2004/04/06 7:23:192004/04/06
To:
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....@wanadoo.nl.net> wrote in message
news:OMYGE1vG...@TK2MSFTNGP11.phx.gbl...

Arthur Hoornweg

未読、
2004/04/06 9:46:432004/04/06
To:
NaraendiraKumar R. R. wrote:

> Looks like you are using the MSXML 3.0 or 4.0 via COM?

Yes.

>
> 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.
>


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?

Martin Honnen

未読、
2004/04/06 12:08:442004/04/06
To:

Arthur Hoornweg wrote:

> NaraendiraKumar R. R. wrote:
>
>> Looks like you are using the MSXML 3.0 or 4.0 via COM?
>
>
> Yes.
>
>>
>> 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.
>>
>
>
> 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?

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/

NaraendiraKumar R.R.

未読、
2004/04/06 19:06:412004/04/06
To:
Without .NET, the method Martin mentioned is the way to go.

-Naraen

----
"Martin Honnen" <maho...@yahoo.de> wrote in message
news:O1eqEe8G...@TK2MSFTNGP11.phx.gbl...

全員に返信
投稿者に返信
転送
新着メール 0 件