473,554 Members | 2,815 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

write XML with line feeds?

Hello World,

any idea how I can convince MSXML.IXMLDOMDo cument 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 12100
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.ne t> wrote in message
news:OM******** ******@TK2MSFTN GP11.phx.gbl...
Hello World,

any idea how I can convince MSXML.IXMLDOMDo cument 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.DOMDocum ent.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.DOMDocum ent.4.0');
xmlDocument.app endChild(xmlDoc ument.createEle ment('gods'));
var element = xmlDocument.cre ateElement('god ');
element.setAttr ibute('name', 'Kibo');
xmlDocument.doc umentElement.ap pendChild(eleme nt);
element = xmlDocument.cre ateElement('god ');
element.setAttr ibute('name', 'Xibo');
xmlDocument.doc umentElement.ap pendChild(eleme nt);
WScript.Echo(xm lDocument.xml);

var indentedDocumen t = new ActiveXObject(' Msxml2.DOMDocum ent.4.0');
var xslIndenter = new ActiveXObject(' Msxml2.DOMDocum ent.4.0');
xslIndenter.asy nc = false;
xslIndenter.loa d('test20040406 Xsl.xml');

xmlDocument.tra nsformNodeToObj ect(xslIndenter , indentedDocumen t);

WScript.Echo(in dentedDocument. xml);

indentedDocumen t.save('test200 40406.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:styleshe et 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*******@yaho o.de> wrote in message
news:O1******** ******@TK2MSFTN GP11.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.DOMDocum ent.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.DOMDocum ent.4.0');
xmlDocument.app endChild(xmlDoc ument.createEle ment('gods'));
var element = xmlDocument.cre ateElement('god ');
element.setAttr ibute('name', 'Kibo');
xmlDocument.doc umentElement.ap pendChild(eleme nt);
element = xmlDocument.cre ateElement('god ');
element.setAttr ibute('name', 'Xibo');
xmlDocument.doc umentElement.ap pendChild(eleme nt);
WScript.Echo(xm lDocument.xml);

var indentedDocumen t = new ActiveXObject(' Msxml2.DOMDocum ent.4.0');
var xslIndenter = new ActiveXObject(' Msxml2.DOMDocum ent.4.0');
xslIndenter.asy nc = false;
xslIndenter.loa d('test20040406 Xsl.xml');

xmlDocument.tra nsformNodeToObj ect(xslIndenter , indentedDocumen t);

WScript.Echo(in dentedDocument. xml);

indentedDocumen t.save('test200 40406.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:styleshe et 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
3255
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 to do is force a vbCrLf if a string is long than 80 characters in a row. So if a string is a total of 500 characters with no line feeds, spaces, or...
1
1296
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 source. But in the label itself on the page in the browser the line feeds are ignored. How can I change the line feeds to HTML syntax (<br/>)?
2
5588
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
1516
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. But if I attempt to add any other terms, such as the sender's name and location, the MIME parameter above seems to ignore the "\n" line feeds and put...
2
3507
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. But if I attempt to add any other terms, such as the sender's name and location, the MIME parameter above seems to ignore the "\n" line feeds and put...
6
1804
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
4206
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 return line feeds (CRLF). However after adding it to an archive and then decompressing the line endings have been converted to just line feeds...
13
2792
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 ($fp); and then parsing them with PHP's native parsing functions. This is succesful for most of the feeds, but a couple of them claim to be
3
1649
by: Anonymous | last post by:
How do I publish a web site (web application .net 2.0) from the command line in VS2008?
2
1966
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 richtx32.ocx rich text box control. We open a form with a rich text control and edit the text. When the text is saved back to the database it adds extra...
0
7499
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8013
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7531
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5414
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5136
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3530
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1994
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1112
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.