all groups > dotnet xml > september 2005 >
You're in the

dotnet xml

group:

Problem transforming empty element tags using XmlTransform


Problem transforming empty element tags using XmlTransform nospam NO[at]SPAM nospam.net
9/1/2005 12:00:00 AM
dotnet xml:
I'm trying to transform an xml file that contains empty short elements like
the following:

<element attrib="abc"/>

using the XmlTransform class. But I cannot seem to preserve the short format
as everytime it get's converted to the longer format of:

<element attrib="abc"></element>

I need to preserve the shorter format, has anyone else had this problem or
got a solution?

Re: Problem transforming empty element tags using XmlTransform Martin Honnen
9/1/2005 12:00:00 AM


[quoted text, click to view]

There are lots of people who report that "problem" but the usual attempt
to "solve" it is to explain that in terms of XML
<element attrib="abc"/>
and
<element attrib="abc"></element>
are absolutely equivalent so any application processing the
transformation output as XML should not have any problems or make a
difference.
Why do you think you need to preserve <element />?

--

Martin Honnen --- MVP XML
Re: Problem transforming empty element tags using XmlTransform Pascal Schmitt
9/2/2005 12:00:00 AM
[quoted text, click to view]

I only use indent="yes" for debugging, later when I'm sure the output is
correct and only read by XML-parsers, I set indent="no".

But IIRC, if you avoid whitespace in the XSLT, there won't be any in the
output either. For example:

<out:element><xslt:attribute name="attrib">
<xslt:value-of select="'foo'" /<
</xslt:attribute></out:element>

xslt:attribute will be replaced, so you can use whitespace inside it.


--
Re: Problem transforming empty element tags using XmlTransform Demon News
9/2/2005 12:00:00 AM
Thanks, I guess I'll just not use indentation. I'm still surprised that this
happens though.

[quoted text, click to view]

Re: Problem transforming empty element tags using XmlTransform Demon News
9/2/2005 9:23:47 AM
They are using Biztalk, and what is actually happening is that <element
attrib="abc"/> is actually being converted to:

<element attrib="abc">
</element>

which, because of the whitespace is causing problems. I could probably get
round this by using the indent="no" parameter in xslt but for readability
that puts everything on one line and I don't see why this should be
happening.

Using Stylus studio to debug things using the MSXML .Net parser doesn't have
this problem so I'm thinking there should be another way round it.

[quoted text, click to view]

Re: Problem transforming empty element tags using XmlTransform Demon News
9/2/2005 11:45:08 AM
Does this mean that there isn't a way of keeping the short tags or you just
don't know of one?

thanks


[quoted text, click to view]

AddThis Social Bookmark Button