BizTalk Server Tools - suppressing explicit end tag in xml

This is Interesting: Free IT Magazines  
Home > Archive > BizTalk Server Tools > July 2005 > suppressing explicit end tag in xml





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author suppressing explicit end tag in xml
Ken

2005-07-05, 5:51 pm

Hi,

I am using xslt (template) to convert my input to output using BTS 2004. In
my output XML, I have certain empty tag elements (for e.g. <name first="ken"
last="xxxx"\> ). When I test my xslt outside BizTalk using other XML tools,
the output is generated properly with empty tag elements printed correctly.

However, when BTS applies the template, it generates o/p xml with explicit
end tags (i.e. <name first="ken" last="xxxx"></name> ). But, this is not
what I want.

Does anyone know how to make BTS spit output with empty tag intact?

Thanks,
Ken
David Carroll

2005-07-19, 5:51 pm

Ken,

****************************************
************
***Explanation of Explicit XML Closing Tag***
****************************************
************
If you are using the BizTalk Mapper to generate the compiled XSLT, then
there is no way to avoid closing tags. However, that is not to say
that BizTalk 2004 couldn't generate XML Output without closing tags.
It's just saying that there is no control over the way the Mapper
generates the XSLT.

The following demonstrates how the Mapper would generate a sample XSLT:

GENERATED XSLT:
<name>
<xsl:if test="@*[local-name()='SourceFirstName' and
namespace-uri()='']">
<xsl:attribute name="first">
<xsl:value-of select="@*[local-name()='SourceFirstName'
and namespace-uri()='']" />
</xsl:attribute>
</xsl:if>
<xsl:if test="@*[local-name()='SourceLastName' and
namespace-uri()='']">
<xsl:attribute name="last">
<xsl:value-of select="@*[local-name()='SourceLastName'
and namespace-uri()='']" />
</xsl:attribute>
</xsl:if>
</name> <!--NOTICE THE CLOSING TAG IS EXPLICITLY DECLARED
HERE-->

OUTPUT: <name first="ken" last="xxx"></name>

In order to generate the same XML without a closing tag the XSLT must
look something like the following:

CUSTOM XSLT:
<name first='{@*[local-name()='SourceFirstName' and
namespace-uri()='']}' last='{@*[local-name()='SourceLastName' and
namespace-uri()='']}'/>
<!--NOTICE THE EMPTY TAG IS EXPLICITLY PRESERVED HERE.-->

NEW OUTPUT: <name first="ken" last="xxx"/>

****************************************
**********
***Don't Be Deceived By the Other Tools***
****************************************
**********
How did you go about testing your XSLT outside of BizTalk. If you are
using the generated XSLT from the BizTalk Mapper and testing that XSLT
in another tool, it's possible the other tool is rendering your closing
tags as empty tags. This happens if you use Internet Explorer to test
your XSLT for example. XML Spy will even reformat any XML with empty
closing tags when switching from grid view to text view.

What other tools did you use to test your XSLT?

Here's a test to try...

Copy the following to a file named TestXML.xml:
<name first="ken" last="xxx"></name>

Now open it in Internet Explorer... You should notice the XML will
appear as: <name first="ken" last="xxx"/>

If you are using XML Spy or something similar, paste the same XML with
closing tag into the editor as text. Then switch to grid view and
return back to text view. You should see the closing tag removed.

Therefore, if you are seeing different results when testing the same
XSLT, it's probably because the tools aren't displaying the true
tranformation output.

***********************************
***ALTERNATE SOLUTION***
***********************************
If it is absolutely necessary to generate XML without closing tags in
general and you do not want to implement custom XSLT in your Mapper, I
recommend cleaning up the XML in a custom Send Pipeline Component.
Investigate using an XMLTextReader to read the outgoing XML Stream and
rewrite the XML with empty tags to exclude closing tags using an
XMLTextWriter to a new Stream. Return this new stream to the Pipeline
and voila..., you've replicated the same type of reformatting behavior
as any third party tool or even IE. Your Send Port will deliver the
reformatted XML Message. This would be a great opportunity to research
custom pipeline components and extend your BizTalk Library and
knowledge.

I hope this information was helpful.

David Carroll

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com