"Token Text in EndRootElement state will result in an invalid XML document"

I see this exception message from XslCompiledTransform.Transform (), but after handling the exception, the XSL transformation still seems successful. Full exception message:

Token text in EndRootElement state will result in an invalid XML document. Make sure the ConformanceLevel parameter is set to ConformanceLevel.Fragment or ConformanceLevel.Auto if you want to write an XML fragment.

The style sheet looks like this:

<xsl:stylesheet version="1.0" xmlns:ext="ext:extensions" xmlns:f="http://schemas.foo.com/FOAMSchema"> <xsl:template match="/Root/Documents/PO/DROPSHIP"> <Transactions> <Transaction> <f:partnerTransmission> <transmission_id> <xsl:value-of select="ext:NewGUID()"/> </transmission_id> <partner_code> <xsl:value-of select="/Root/@PartnerCode"/> </partner_code> <control_nbr> <xsl:value-of select="@GS_CNTRL_NUM"/> </control_nbr> <creationTime> <xsl:value-of select="ext:ConvertToStandardDateTime(@DATE,@TIME,'ISO8601Basic')"/> </creationTime> <direction>I</direction> <messageCount> <xsl:value-of select="count(ORDERS/ORDER)"/> </messageCount> <syntax>XML</syntax> <format>BARBAZ</format> <deliveryMethod>FTP</deliveryMethod> </f:partnerTransmission> </Transaction> </Transactions> </xsl:template> </xsl:stylesheet> 

The generated XML is as follows:

 <Transactions xmlns="http://schemas.foo.com/IntegrationProfile" xmlns:ext="ext:extensions"> <Transaction> <f:partnerTransmission xmlns:f="http://schemas.foo.com/FOAMSchema"> <transmission_id>a5e0ec76-6c24-426b-9eb5-aef9c45d913f</transmission_id> <partner_code>VN000033</partner_code> <control_nbr>650</control_nbr> <creationTime>9/27/2008 12:51:00 AM</creationTime> <direction>I</direction> <messageCount>2</messageCount> <syntax>XML</syntax> <format>BARBAZ</format> <deliveryMethod>FTP</deliveryMethod> </f:partnerTransmission> </Transaction> </Transactions> 

The above is what I get when I catch and ignore the exception.

I was not able to find a way to set ConformanceLevel (the property is read-only), but at the same time I also don't think there should be a problem here anyway.

Is my output an XML snippet? Am I missing something in the stylesheet?

+4
source share
2 answers

An exception tries to tell you that you tried to print text after the close element of the root element. The reason your output looks fine is because the exception prevented the creation of invalid XML.

The reason is simple: you do not have a conversion for the document root. Therefore, default conversions are performed. They will display the text content of all elements as text nodes.

Add

 <xsl:template match="/"> <xsl:apply-templates select="/Root/Documents/PO/DROPSHIP"/> </xsl:template> 
+7
source

Your output is a well-formed piece of XML. In other words, it looks good, and your XSLT too.

The error message seems to be trying to tell you the following:

Using this XSLT creates an invalid document according to the DTD or Schema, or whatever I use to verify the output, and my conformanceLevel tells me that I am complaining about the invalid output. If you don't need authenticity, set conformanceLevel to something less anal.

Note the important difference between “well-formed” (a consistent non-validating XML parser can read it) and “valid” (the structure does not match the grammar specified in the schema).

Also note that in XSLT it is not possible to create output that is not valid XML.

0
source

All Articles