473,378 Members | 1,390 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

write XML with line feeds?

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
4 12086
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" <ar*************@wanadoo.nl.net> wrote in message
news:OM**************@TK2MSFTNGP11.phx.gbl...
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 #2
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?
--
Arthur Hoornweg
(please remove the ".net" from my e-mail address)
Nov 12 '05 #3


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/

Nov 12 '05 #4
Without .NET, the method Martin mentioned is the way to go.

-Naraen

----
"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:O1**************@TK2MSFTNGP11.phx.gbl...


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/

Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Jason | last post by:
When users fill out my text area field, there is a chance that there will be no line feeds or cariage returns or spaces and just one really long word. THIS CAUSES A MAJOR PROBLEM! What I am trying...
1
by: Frank Esser | last post by:
Hello, I read data from a DB field where a line feed ("\n") is in. I put this data as text to a label web control. In the HTML page the line feeds are shown as real line feeds in the HTML...
2
by: jcb | last post by:
The following code in Python 2.3 f = file('t.txt', 'wt') f.write('\n') f.close() writes 0D0A to the file. Is this a bug or expected behavior? It sure took me by surprise.
0
by: bobkaku | last post by:
I added "MIME-Version: 1.0\r\nContent-Type:text/html; charset=iso-8859-1\r\n" as one of the parameters in the mail( ) function to replace the "Nobody" with a real From: email. That worked. ...
2
by: bobkaku | last post by:
I added "MIME-Version: 1.0\r\nContent-Type:text/html; charset=iso-8859-1\r\n" as one of the parameters in the mail( ) function to replace the "Nobody" with a real From: email. That worked. ...
6
by: cookspyder | last post by:
Im trying to tail a file that does not have hard returns but has line feeds after each entry. Is there a way to change the standard file tail settings to look for line feeds when tailing?
3
by: towers | last post by:
Hi I'm probably doing something stupid but I've run into a problem whereby I'm trying to add a csv file to a zip archive - see example code below. The csv just has several rows with carriage...
13
by: charliefortune | last post by:
I am fetching some product feeds with PHP like this $merch = substr($key,1); $feed = file_get_contents($_POST); $fp = fopen("./feeds/feed".$merch.".txt","w+"); fwrite ($fp,$feed); fclose...
3
by: Anonymous | last post by:
How do I publish a web site (web application .net 2.0) from the command line in VS2008?
2
by: tom0550 | last post by:
Around December 2008 our MS Access 2003 application started inserting extra line feeds everytime the RTF edit window was opened and saved. It was working fine up to that time. We are using the MS...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.