Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Carriage Returns afther closing tag 1

Status
Not open for further replies.

pkailas

Programmer
Jun 10, 2002
555
US
I have a client that has a "home grown" xml parser that they use to load their application from an XML file we provide them. However, since they are not using the MSXML parser, they require a vbCr after each closing Tag.

Does anyone know if MSXML objects can even be instructed to do this? If so how? And if not, has anyone had to do any hacks to perform this?

Thanks in advance.

Paul

_______
I love small animals, especially with a good brown gravy....
 
Paul,

Are you using XSLT? If so, you might see if the indent attribute on the xsl:eek:utput element does the trick.

Otherwise, you could write a variant of an identity transform that does this with brute force, output in text mode which ensures an end-of-line after each closing element tag. The following could be used as a starting point...it is cobbled together from a previous use, and is not necessarily working as is. Note that line feeds inside xsl:text are significant.
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
   <xsl:output method="text" encoding="UTF-8"  omit-xml-declaration="yes"/>
   <xsl:template match="/" >
<xsl:text disable-output-escaping="yes">&lt;Data&gt;&lt;![CDATA[&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
</xsl:text>
   <xsl:apply-templates select="*" mode="replicate" /> 
   </xsl:template>

   <xsl:template match="*" mode="replicate">
    <xsl:if test="boolean(.//text()) or boolean(string(@*)) or boolean(text())" >
     <xsl:text disable-output-escaping="yes">&lt;</xsl:text>
     <xsl:value-of select="name()"/>
     <xsl:for-each select="@*">
       <xsl:text> </xsl:text>
       <xsl:value-of select="name()" />
       <xsl:text disable-output-escaping="yes">=&quot;</xsl:text>
       <xsl:value-of select="." />
       <xsl:text disable-output-escaping="yes">&quot;</xsl:text>
     </xsl:for-each>
     <xsl:text disable-output-escaping="yes">&gt;</xsl:text>
	 <xsl:if test="boolean(count(*))">
	   <xsl:text disable-output-escaping="yes">
</xsl:text>
	 </xsl:if>
     <xsl:apply-templates select="*|text()" mode="replicate" />
     <xsl:text disable-output-escaping="yes">&lt;/</xsl:text>
     <xsl:value-of select="name()"/>
     <xsl:text disable-output-escaping="yes">&gt;
</xsl:text>
	</xsl:if>
   </xsl:template>
   <xsl:template match="text()" mode="replicate">
	<xsl:if test="string-length(normalize-space(.)) > 0">
		<xsl:value-of select="."/>
	</xsl:if>
   </xsl:template>
</xsl:stylesheet>

Tom Morrison
 
>Does anyone know if MSXML objects can even be instructed to do this?
In what sense? If you build yourself the xml document source file by msxml2's domdocument, you can append a textnode of carriage return to the parentNode everytime you append an element node to it. Figuratively like this in vb/vba/vbs.
[tt]
' refencence oparser be the DOMDocument
' reference oparentnode be an element node IXMLDomElement
' reference oelem be the some created IXMLDomElement
[blue]' whenever you do this[/blue]
oparentnode.appendChild oelem
[blue]' you immediately follow it by adding this line
oparentnode.appendChild oparser.createtextnode(vbcrlf)[/blue]
'etc etc
[/tt]
 
k5tm,

Thanks for helping, but I'm using DOM MSXML and not XLS.

tsuji's method works for everything but the first child node. Hopefully I don't need to have a carriage return after that one. Waiting on the Client's response before I close this issue.

Paul

_______
I love small animals, especially with a good brown gravy....
 
>...'s method works for everything but the first child node.
Now that you know the basic of how thing got done at creation level, why don't you adapt to the situation? When the oelem or document root is still empty, you immediately add the line of createtextnode(vbcrlf) and then continue building its content?
 
Like I said I got everything but one node to have a carriage return. I sent the resulting file to the client and they successfully used the file. As they are not using a true XML parser, I wasn't going to kill myself trying to make a non-standard file unless I needed to.

Your help was all I needed.

Thanks a lot!!

_______
I love small animals, especially with a good brown gravy....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top