Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Sun, 22 Jun 2008 00:18:51 +0200,    group: microsoft.public.xml        back       


xml formatting   
Hello,

how can I save formatted xmldom without inserting text-nodes?

I mean, when I create xml tree via
        srcxml.transformNodeToObject(xslt, dstxml)
where the xslt contains
        <xsl:output method="xml" indent="yes" />
and save the result
        dstxml.save(path)
then the resulting xml file is well formatted. E.g.
        <parent>
            <child/>
            <child/>
        </parent>

However, when before saving dstxml I do several times
        someNode.appendChild(dstxml.createElement("test"))
the newly inserted nodes appear as
        <parent>
            <child/>
            <child/>
            <test/><test/></parent>
on a single line without spaces. This is still not surprising as I inserted 
no text nodes in between the <test/> elements.

What surprises me is that the nodes resulting from xslt do NOT contain text 
nodes in between either, but this doesn't prevent them from being formatted. 
The <parent> element in the example above contains two childNodes, there are 
no text nodes.

I'd like to know, how to achieve the same result using DOM.

Thank you,
            Martin.

P.S. I've forgotten to mention that I use "MSXML2.DOMDocument" progId, which 
references MSXML6.
date: Sun, 22 Jun 2008 00:18:51 +0200   author:   Martin Plecher

Re: xml formatting   
"Martin Plecher"  wrote in message 
news:e6OWxy#0IHA.5832@TK2MSFTNGP02.phx.gbl...
> Hello,
>
> how can I save formatted xmldom without inserting text-nodes?
>
> I mean, when I create xml tree via
>        srcxml.transformNodeToObject(xslt, dstxml)
> where the xslt contains
>        <xsl:output method="xml" indent="yes" />
> and save the result
>        dstxml.save(path)
> then the resulting xml file is well formatted. E.g.
>        <parent>
>            <child/>
>            <child/>
>        </parent>
>
> However, when before saving dstxml I do several times
>        someNode.appendChild(dstxml.createElement("test"))
> the newly inserted nodes appear as
>        <parent>
>            <child/>
>            <child/>
>            <test/><test/></parent>
> on a single line without spaces. This is still not surprising as I 
> inserted no text nodes in between the <test/> elements.
>
> What surprises me is that the nodes resulting from xslt do NOT contain 
> text nodes in between either, but this doesn't prevent them from being 
> formatted. The <parent> element in the example above contains two 
> childNodes, there are no text nodes.
>
> I'd like to know, how to achieve the same result using DOM.
>
> Thank you,
>            Martin.
>
> P.S. I've forgotten to mention that I use "MSXML2.DOMDocument" progId, 
> which references MSXML6.
>
You could apply an XSLT at the final stage:

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent="yes" />
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

I would have thought that to use version 6.0 you'd need 
MSXML2.DOMDocument.6.0 or MSXML2.DOMDocument60 depending on if you are using 
script.

-- 

Joe Fawcett (MVP - XML)
http://joe.fawcett.name
date: Sun, 22 Jun 2008 08:53:12 +0100   author:   Joe Fawcett am

Re: xml formatting   
Martin Plecher wrote:

> What surprises me is that the nodes resulting from xslt do NOT contain text 
> nodes in between either, but this doesn't prevent them from being formatted. 
> The <parent> element in the example above contains two childNodes, there are 
> no text nodes.

That is indeed surprising but you can get the text nodes in the DOM by 
setting
   dstxml.preserveWhiteSpace = true
before you load or transform to dstxml.

> I'd like to know, how to achieve the same result using DOM.

As already suggested, run an XSLT identity transformation with 
xsl:output indent="yes" before you save. Or you will have to use DOM 
createTextNode and appendChild/insertBefore to insert the text nodes for 
formatting yourself.



-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
date: Sun, 22 Jun 2008 15:14:47 +0200   author:   Martin Honnen

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us