Discussion:
Creating XML files using MSXML
(too old to reply)
WAkthar
2005-07-14 14:08:17 UTC
Permalink
Hi,

I am creating a customised xml file using msxml.
The xml file is created correctly apart from one problem.
How do I add put tags on new lines.
For example if I have an xml file as

<timeline version="1.0">
<group type="Video" width="352" height="288" framerate="25">
<track name="Video">
Video1
</track>
</group>
</timeline>

When I create this using msxml, it appears on one line as

<timeline omni_version="1.0"><group type="Video" width="352" height="288"
framerate="25"><track name="Video">

Is there a way I can say that after every tag, I want to indent the next on
a new line as above ??

Cheers
Carl Daniel [VC++ MVP]
2005-07-14 15:43:34 UTC
Permalink
Post by WAkthar
Hi,
I am creating a customised xml file using msxml.
The xml file is created correctly apart from one problem.
How do I add put tags on new lines.
For example if I have an xml file as
<timeline version="1.0">
<group type="Video" width="352" height="288" framerate="25">
<track name="Video">
Video1
</track>
</group>
</timeline>
When I create this using msxml, it appears on one line as
<timeline omni_version="1.0"><group type="Video" width="352"
height="288" framerate="25"><track name="Video">
Is there a way I can say that after every tag, I want to indent the
next on a new line as above ??
AFIAK, no. The whitespace between tags has to be part of the XMLDomDocument
in order to be part of the string that's returned by the xml property or
written by the save method.

You could use an XSLT stylesheet to add the necessary whitespace nodes - do
a bit of searching around the net, I bet there's one out there somewhere.

-cd
WAkthar
2005-07-14 16:27:24 UTC
Permalink
What is AFIAK?
Post by Carl Daniel [VC++ MVP]
Post by WAkthar
Hi,
I am creating a customised xml file using msxml.
The xml file is created correctly apart from one problem.
How do I add put tags on new lines.
For example if I have an xml file as
<timeline version="1.0">
<group type="Video" width="352" height="288" framerate="25">
<track name="Video">
Video1
</track>
</group>
</timeline>
When I create this using msxml, it appears on one line as
<timeline omni_version="1.0"><group type="Video" width="352"
height="288" framerate="25"><track name="Video">
Is there a way I can say that after every tag, I want to indent the
next on a new line as above ??
AFIAK, no. The whitespace between tags has to be part of the
XMLDomDocument in order to be part of the string that's returned by the
xml property or written by the save method.
You could use an XSLT stylesheet to add the necessary whitespace nodes -
do a bit of searching around the net, I bet there's one out there
somewhere.
-cd
David Webber
2005-07-14 16:37:47 UTC
Permalink
"WAkthar" <***@hotmail.com> wrote in message news:***@TK2MSFTNGP10.phx.gbl...

What is AFIAK?

As far as I know it's AFAIK

Dave
--
David Webber
Author MOZART the music processor for Windows -
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mzusers/mailinglist.htm
Alex Blekhman
2005-07-14 18:32:34 UTC
Permalink
Post by Carl Daniel [VC++ MVP]
Post by WAkthar
Is there a way I can say that after every tag, I want to
indent the next on a new line as above ??
AFIAK, no. The whitespace between tags has to be part of
the XMLDomDocument in order to be part of the string
that's returned by the xml property or written by the
save method.
Actually, no. You can create XML text element (IXMLDOMText)
programmatically without a problem. Here's little example
(written in JScript for simplicity):

-------
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
xmlDoc.async = false;

// preserveWhiteSpace is useful when loading
// existing documents.
xmlDoc.preserveWhiteSpace = true;

xmlDoc.appendChild(xmlDoc.createElement("root"));

xmlDoc.documentElement.appendChild(
xmlDoc.createTextNode("\r\n\t"));

xmlDoc.documentElement.appendChild(
xmlDoc.createElement("child"));

xmlDoc.documentElement.appendChild(
xmlDoc.createTextNode("\r\n"));

xmlDoc.save("test.xml");
-------

Resulting XML will be:

<root>
<child/>
</root>
Alex Blekhman
2005-07-14 18:35:29 UTC
Permalink
Actually, no. [...]
Sorry, I misread your first sentence. I meant that you don't
need additional XSL to insert white spaces/indentation.
Carl Daniel [VC++ MVP]
2005-07-14 20:00:00 UTC
Permalink
Post by Alex Blekhman
Actually, no. [...]
Sorry, I misread your first sentence. I meant that you don't
need additional XSL to insert white spaces/indentation.
No, you certainly don't need it. It might be a better solution in some
cases, since a single XSLT stylesheet could be developed that would do
"canonical indentation" of any Xml document.

-cd
Eugene Gershnik
2005-07-14 23:15:16 UTC
Permalink
Post by WAkthar
Is there a way I can say that after every tag, I want to indent the
next on a new line as above ??
Yes. Use MXXMLWriter and set its indent property. See

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/6139a6fe-7d4c-449d-9e36-60b68be1de71.asp

for details. You will need to create a SAX reader to read your DOM doc, then
let the reader write to the writer.
--
Eugene
http://www.gershnik.com
Carl Daniel [VC++ MVP]
2005-07-14 23:23:07 UTC
Permalink
Post by Eugene Gershnik
Post by WAkthar
Is there a way I can say that after every tag, I want to indent the
next on a new line as above ??
Yes. Use MXXMLWriter and set its indent property. See
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/6139a6fe-7d4c-449d-9e36-60b68be1de71.asp
for details. You will need to create a SAX reader to read your DOM
doc, then let the reader write to the writer.
Thanks! I just *knew* I'd found a built-in way to do it before, but it's
been too long since I was deep in MSXML to dredge that up anymore.

-cd

Continue reading on narkive:
Loading...