我有如下的xml,
<?xml version="1.0" encoding="utf-16" ?>
<AllResidentAndUnitInfo xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
i:type="ResidentsByUnitInfo" xmlns="http://schemas.datacontract.org/2004/07/FSRSchema">
<BillingAddresses>
<BillingAddress>
<billing_address1>Some address</billing_address1>
<billing_address2 />
<billing_city>Gilbert</billing_city>
<billing_country i:nil="true"/>
<billing_dtmmodified>2010-12-08T01:37:41+05:30</billing_dtmmodified>
<billing_state>AZ</billing_state>
<billing_zipcode>23233</billing_zipcode>
</BillingAddress>
<BillingAddress>
<ResidentsByUnitInfoPropertyUnitBillingAddress>
<billing_address1>Some address</billing_address1>
<billing_address2 />
<billing_city>Gilbert</billing_city>
<billing_country i:nil="true"/>
<billing_dtmmodified>2010-12-08T01:37:41+05:30</billing_dtmmodified>
<billing_state>AZ</billing_state>
<billing_zipcode>23233</billing_zipcode>
</ResidentsByUnitInfoPropertyUnitBillingAddress>
</BillingAddress>
....
</AllResidentAndUnitInfo>
我正在使用 XslCompiledTransform 在 C# 中转换为另一种 xml 格式,
<?xml version='1.0' ?>
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
xmlns:msxsl='urn:schemas-microsoft-com:xslt'
xmlns:i='http://www.w3.org/2001/XMLSchema-instance' exclude-result-prefixes='msxsl
i' version='1.0'>
<xsl:output method='xml' indent='yes'/>
<xsl:template match='/AllResidentAndUnitInfo/BillingAddresses/BillingAddress'>
<Root>
<Address1>..</Address2>
...
</Root>
</xsl:template>
</xsl:stylesheet>
我收到错误“处于 Start 状态的令牌文本将导致无效的 XML 文档。如果要编写 XML 片段,请确保将 ConformanceLevel 设置设置为 ConformanceLevel.Fragment 或 ConformanceLevel.Auto。”我知道问题出在 xml 中的 i:nil 属性上。尽管我将它们的名称空间包含在 XSLT 中,但我仍然收到错误。
我收到错误“开始状态下的令牌文本将导致
无效的 XML 文档。确保 ConformanceLevel 设置为
如果需要,设置为 ConformanceLevel.Fragment 或 ConformanceLevel.Auto
编写 XML 片段。”我知道问题在于 i:nil
xml 中的属性。尽管我将它们的命名空间包含在
XSLT 我仍然收到错误。
不。问题是结果不是格式良好的 XML 文档因此XmlWriter
参与将结果树最终序列化为文本,引发此异常。
真的,在你的结果中有两个Root
元素并且它们都没有父元素。
您需要生成格式良好的文档,或者更改一致性级别 http://msdn.microsoft.com/en-us/library/system.xml.xmlwritersettings.conformancelevel.aspx设置为XmlWriter
to ConformanceLevel.Fragment
or ConformanceLevel.Auto
.
要创建格式正确的输出,只需添加:
<xsl:template match="/">
<top>
<xsl:apply-templates/>
</top>
</xsl:template>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)