0

我设计了一个 xml 模式来解析传入的 xml 文档。接收位置从 2 个提要获取 xml 文档,其中一个在文档中拼错了一个节点,“Roookie”而不是“Rookie”,有没有办法让我现有的 xsd 解析这个文档?

4

4 回答 4

2

您可能会预处理错误的 XML 文件,例如使用这个简单的 XSL 样式表:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="no"/>

<xsl:template match="Roookie">
        <Rookie>
                <xsl:apply-templates select="@*|node()" />
        </Rookie>
</xsl:template>

<xsl:template match="@*|node()" name="defaultRule">
        <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
</xsl:template>

</xsl:stylesheet>
于 2008-11-19T21:31:09.170 回答
0

The onyl answer here is to modify the bad message. The xsd is a contract and should be adhered to by submitting systems. If you don't have this kind of control over the submitting systems, I'd suggest making a second schema with a new name and have it accomodate the spelling error. I fyou start altering your contract/xsd for every mistake in a message, you will increase complexity and decrease maintainability.

于 2008-12-05T03:38:51.420 回答
0

您需要替换文档中的元素或修改 xsd 以使用新的文档格式。

于 2008-11-19T21:21:03.260 回答
0

只需修改您的模式以接受 2 个节点(Rookie 或 Roookie)之间的选择,而不是简单的 1 个名为 Rookie 的节点。两个节点具有相同的类型。当然,如果 Roo(o)kie 有一个复杂的内容,你会想要为这个内容声明一个复杂的类型,以避免重复 2 个元素的整个结构。

于 2008-11-19T21:30:18.250 回答