"国有EndRootElement令牌文本会导致无效XML文档&QUOT的; [英] "Token Text in state EndRootElement would result in an invalid XML document"

查看:184
本文介绍了"国有EndRootElement令牌文本会导致无效XML文档&QUOT的;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到),此异常消息XslCompiledTransform.Transform(着落,但处理后的异常XSL转换似乎仍是成功的。完整的异常消息是:

I'm seeing this exception message coming from XslCompiledTransform.Transform(), but after handling the exception the XSL transform still appears to have been successful. The full exception message is:

令牌中的文本状态EndRootElement   会导致一个无效的XML   文件。确保   ConformanceLevel设置被设置为   ConformanceLevel.Fragment或   ConformanceLevel.Auto如果你想   编写XML片段。

Token Text in state EndRootElement would result in an invalid XML document. Make sure that the ConformanceLevel setting is set to ConformanceLevel.Fragment or ConformanceLevel.Auto if you want to write an XML fragment.

样式表看起来是这样的:

The stylesheet 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>

生成的XML如下所示:

The generated XML looks like this:

<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.

我一直没能找到一种方法来设置ConformanceLevel(该属性为只读),但同时我也不认为应该有一个问题在这里呢。

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

我是否构成输出XML片段?我缺少的东西在样式表?

Does my output constitute an XML fragment? Am I missing something in the stylesheet?

推荐答案

例外是想告诉你,你已经根元素的紧密元素后试图输出文本。之所以你的输出看起来不错是例外的 prevented 的无效XML的产生。

The exception is trying to tell you that you have attempted to output text after the close element of the root element. The reason your output looks ok is that the exception prevented the invalid XML from being generated.

原因很简单:你没有一个变换的文档的根。因此,默认变换被执行。这些将输出的所有元素作为文本节点的文本内容。

The reason is simple: you don't have a transform for the root of the document. Therefore, the default transformations are performed. These will output the text content of all elements as text nodes.

添加

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

这篇关于&QUOT;国有EndRootElement令牌文本会导致无效XML文档&QUOT的;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆