Create xml with formatting

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi,
I have to make a formatted (indented) xml file like this :

<?xml version="1.0"?>
<Message>
<Parent index="0" length="6">123
<Child1 index="0,1" length="6">abcd</Child1>
<Child2 index="0,2" length="6">pqrsxyz</Child2>
</Parent>
</Message>

As you can see, <Parent> node has some innertext as well as child nodes.
But, if
I make xml like this the indentation is lost. The resultant xml is like
this :

<?xml version="1.0"?>
<Message>
<Parent index="0" length="6">123<Child1 index="0,1"
length="6">99</Child1><Child2 index="0,2" length="6">pqrsxyz</Child2></Parent>
</Message>

To sum up the problem, if a node has both innertext and some child nodes,
then the entire node is written in a single line, without indentation.
How can I get the indentation in the above case??
Any help is highly appreciated.

Thanks.
.



Relevant Pages

  • Re: Create xml with formatting
    ... node has some innertext as well as child nodes. ... > I make xml like this the indentation is lost. ... > then the entire node is written in a single line, without indentation. ...
    (microsoft.public.dotnet.general)
  • Re: Create xml with formatting
    ... > To sum up the problem, if a node has both innertext and some child nodes, ... > then the entire node is written in a single line, without indentation. ...
    (microsoft.public.dotnet.general)
  • Re: Creating an XML document ?
    ... Trying to get the indentation right by ... runtime code that "prints" the tabs one way or another. ... where make_tabs returns a string of tabs. ... The other option you've got is perhaps generate the xml without any ...
    (comp.lang.c)
  • Re: CrLf in XML ?
    ... and indentation is mainly to make things easier for human readers. ... However, the XML ... be clearly a one-line long string. ... Is there a way to tell the DOMDocument object to generate the latter? ...
    (microsoft.public.access.externaldata)
  • Re: Xml indent problem
    ... Well, XSLT could be used, with a stylesheet that has its xsl:output directive set to indent (and possibly additional implementation-specific settings to say how much indentation to use; Xalan defaults to indenting by 0, for historical reasons). ... Changing the indentation of XML risks changing the _MEANING_ of the XML, ...
    (comp.text.xml)