报告相应模式的所有未使用元素(+属性)
Report all non used elements (+attributes) of corresponding schema
在这个话题中,我想问的脑细胞比我自己能提供的要多得多。我想根据实际 XML 实例中使用的 used/not 元素(仅限单个名称空间)重构我的 XSD (v1.0)。让我们建立一个小的场景:
我只有针对相应架构的有效 XML 文档:
<body>
<h1>Heading 1</h1>
<p>paragraph</p>
<p><bold>bold</bold>paragraph<italic>italic</italic></p>
</body>
XSD 验证依据:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="body">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element ref="h1"/>
<xs:element ref="h2"/>
<xs:element ref="p"/>
<xs:element ref="span"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="h1" type="xs:string"/>
<xs:element name="h2" type="xs:string"/>
<xs:element name="p">
<xs:complexType mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="bold"/>
<xs:element ref="italic"/>
<xs:element ref="underline"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="span">
<xs:complexType mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="bold"/>
<xs:element ref="italic"/>
<xs:element ref="underline"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="bold" type="xs:NCName"/>
<xs:element name="italic" type="xs:NCName"/>
<xs:element name="underline" type="xs:NCName"/>
</xs:schema>
在此基础上,我想创建一份报告(通过 XSLT [2.0、3.0 通过 SAXON EE 9.6.0.5 可用])关于哪些元素(标签 + 属性)NOT 在我的 XML 实例中使用,但在我的 XSD 实例中是可能的。
简化伪待办事项/从头开始:
- 在我的 XSD.
中搜索所有 //xs:element[@name]
(报告 v2.0 中的属性)
- 在我的 XML
中搜索所有 *
- "compare"它
问题:
可爱的 XSLT 社区中关于这个主题的内容是否已经超出了我的视野?
如何存储比较好?
通过 XSLT 3.0 使用 xsl:map
?存储路径 [/body/h1
,/body/p
] 并比较这些路径? (棘手:从模式中获取正确的路径,处理所有定义方式,如 xs:group ref="..."
或通过 complexTypes
等)
[AddOn:也许我必须将它扩展到我的 XML 中祖先元素的上下文中。在这个例子中,我可能想要
区分 //p/underline
和 //span/underline
.]
<xsl:message>please write your thoughts open minded. I don't request for fully functional code!</xsl:message>
研究 http://saxonica.com/html/documentation/functions/saxon/type.html and http://saxonica.com/html/documentation/functions/saxon/schema.html to get schema type information in Saxon EE on your nodes, that is hopefully a way to compare your instance to the schema. I have never used that so I am not sure how far you will get, I am sure if you add the saxon 您的问题,然后 Michael Kay 会在适当的时候给您一些更好的见解。
你的 post 让我想起了 com.saxonica.Validate 命令的一个选项:通过指定 -stats:report.xml 你应该得到一份关于架构组件使用情况的报告实例文档。它似乎在 9.7 中不起作用(我已经提出了一个错误),但是在 9.5 中你会得到一个形式的报告:
<schemaCoverage>
<component kind="element" namespace="" name="PUB-DATE" count="6"/>
<component kind="complexType" namespace="" name="weightType" count="6"/>
<component kind="element" namespace="" name="PUBLISHER" count="6"/>
<component kind="element" namespace="" name="AUTHOR" count="6"/>
<component kind="element" namespace="" name="DIMENSIONS" count="6"/>
<component kind="simpleType" namespace="" name="languageType" count="6"/>
<component kind="element" namespace="" name="QUANTITY" count="6"/>
<component kind="element" namespace="" name="CATEGORY" count="3"/>
<component kind="complexType"
namespace="http://ns.saxonica.com/anonymous-type"
name="CATEGORIES_anonymous_type_1_at_line_23_of_books.xsd"
count="1"/>
<component kind="element" namespace="" name="LANGUAGE" count="6"/>
<component kind="element" namespace="" name="PAGES" count="6"/>
<component kind="complexType" namespace="" name="moneyType" count="6"/>
<component kind="element" namespace="" name="ISBN" count="6"/>
<component kind="simpleType"
namespace="http://www.w3.org/2001/XMLSchema"
name="IDREF"
count="6"/>
<component kind="simpleType"
namespace="http://www.w3.org/2001/XMLSchema"
name="ID"
count="3"/>
<component kind="complexType"
namespace="http://ns.saxonica.com/anonymous-type"
name="BOOKS_anonymous_type_1_at_line_14_of_books.xsd"
count="1"/>
<component kind="element" namespace="" name="CATEGORIES" count="1"/>
<component kind="simpleType" namespace="" name="ISBNType" count="6"/>
<component kind="simpleType"
namespace="http://www.w3.org/2001/XMLSchema"
name="string"
count="22"/>
<component kind="complexType"
namespace="http://ns.saxonica.com/anonymous-type"
name="ITEM_anonymous_type_1_at_line_39_of_books.xsd"
count="6"/>
<component kind="simpleType" namespace="" name="weightUnitType" count="6"/>
<component kind="complexType"
namespace="http://ns.saxonica.com/anonymous-type"
name="CATEGORY_anonymous_type_1_at_line_31_of_books.xsd"
count="3"/>
<component kind="simpleType"
namespace="http://www.w3.org/2001/XMLSchema"
name="date"
count="6"/>
<component kind="simpleType"
namespace="http://www.w3.org/2001/XMLSchema"
name="integer"
count="12"/>
<component kind="element" namespace="" name="TITLE" count="6"/>
<component kind="element" namespace="" name="PRICE" count="6"/>
<component kind="element" namespace="" name="WEIGHT" count="6"/>
<component kind="complexType" namespace="" name="dimensionsType" count="6"/>
<component kind="element" namespace="" name="ITEM" count="6"/>
<component kind="simpleType" namespace="" name="lengthUnitType" count="6"/>
<component kind="element" namespace="" name="BOOKS" count="1"/>
</schemaCoverage>
这似乎正是您要找的。
我为 XSLT 3.0 测试套件做了一个类似这样的练习。您可以在此处找到样式表:
https://dvcs.w3.org/hg/xslt30-test/file/24e8b98b044b/tests/misc/catalog/catalog-007.xsl
需要两个输入:
(a) 使用带有 -scmout 选项的 com.saxonica.Validate 生成的 SCM 文件,应用于 schema-for-xslt30。 SCM 文件是编译模式的表示,从 XSLT 分析比原始源模式更容易分析
(b) 测试套件中的非错误样式表集,通过递归搜索测试元数据目录获得。
它提取模式允许的 element-name/attribute-name 对集,然后提取样式表中实际存在的 element-name/attribute-name 对集(在每种情况下都经过过滤,例如仅考虑元素XSLT 命名空间)。然后它比较两个列表,并报告模式允许但测试样式表中不存在的任何对,以及测试样式表中存在但模式不允许的任何对。只有当两个列表都为空时,测试才会通过。
在这个话题中,我想问的脑细胞比我自己能提供的要多得多。我想根据实际 XML 实例中使用的 used/not 元素(仅限单个名称空间)重构我的 XSD (v1.0)。让我们建立一个小的场景:
我只有针对相应架构的有效 XML 文档:
<body>
<h1>Heading 1</h1>
<p>paragraph</p>
<p><bold>bold</bold>paragraph<italic>italic</italic></p>
</body>
XSD 验证依据:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="body">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element ref="h1"/>
<xs:element ref="h2"/>
<xs:element ref="p"/>
<xs:element ref="span"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="h1" type="xs:string"/>
<xs:element name="h2" type="xs:string"/>
<xs:element name="p">
<xs:complexType mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="bold"/>
<xs:element ref="italic"/>
<xs:element ref="underline"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="span">
<xs:complexType mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="bold"/>
<xs:element ref="italic"/>
<xs:element ref="underline"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="bold" type="xs:NCName"/>
<xs:element name="italic" type="xs:NCName"/>
<xs:element name="underline" type="xs:NCName"/>
</xs:schema>
在此基础上,我想创建一份报告(通过 XSLT [2.0、3.0 通过 SAXON EE 9.6.0.5 可用])关于哪些元素(标签 + 属性)NOT 在我的 XML 实例中使用,但在我的 XSD 实例中是可能的。
简化伪待办事项/从头开始:
- 在我的 XSD. 中搜索所有
- 在我的 XML 中搜索所有
- "compare"它
//xs:element[@name]
(报告 v2.0 中的属性)
*
问题:
可爱的 XSLT 社区中关于这个主题的内容是否已经超出了我的视野?
如何存储比较好?
通过 XSLT 3.0 使用 xsl:map
?存储路径 [/body/h1
,/body/p
] 并比较这些路径? (棘手:从模式中获取正确的路径,处理所有定义方式,如 xs:group ref="..."
或通过 complexTypes
等)
[AddOn:也许我必须将它扩展到我的 XML 中祖先元素的上下文中。在这个例子中,我可能想要
区分 //p/underline
和 //span/underline
.]
<xsl:message>please write your thoughts open minded. I don't request for fully functional code!</xsl:message>
研究 http://saxonica.com/html/documentation/functions/saxon/type.html and http://saxonica.com/html/documentation/functions/saxon/schema.html to get schema type information in Saxon EE on your nodes, that is hopefully a way to compare your instance to the schema. I have never used that so I am not sure how far you will get, I am sure if you add the saxon 您的问题,然后 Michael Kay 会在适当的时候给您一些更好的见解。
你的 post 让我想起了 com.saxonica.Validate 命令的一个选项:通过指定 -stats:report.xml 你应该得到一份关于架构组件使用情况的报告实例文档。它似乎在 9.7 中不起作用(我已经提出了一个错误),但是在 9.5 中你会得到一个形式的报告:
<schemaCoverage>
<component kind="element" namespace="" name="PUB-DATE" count="6"/>
<component kind="complexType" namespace="" name="weightType" count="6"/>
<component kind="element" namespace="" name="PUBLISHER" count="6"/>
<component kind="element" namespace="" name="AUTHOR" count="6"/>
<component kind="element" namespace="" name="DIMENSIONS" count="6"/>
<component kind="simpleType" namespace="" name="languageType" count="6"/>
<component kind="element" namespace="" name="QUANTITY" count="6"/>
<component kind="element" namespace="" name="CATEGORY" count="3"/>
<component kind="complexType"
namespace="http://ns.saxonica.com/anonymous-type"
name="CATEGORIES_anonymous_type_1_at_line_23_of_books.xsd"
count="1"/>
<component kind="element" namespace="" name="LANGUAGE" count="6"/>
<component kind="element" namespace="" name="PAGES" count="6"/>
<component kind="complexType" namespace="" name="moneyType" count="6"/>
<component kind="element" namespace="" name="ISBN" count="6"/>
<component kind="simpleType"
namespace="http://www.w3.org/2001/XMLSchema"
name="IDREF"
count="6"/>
<component kind="simpleType"
namespace="http://www.w3.org/2001/XMLSchema"
name="ID"
count="3"/>
<component kind="complexType"
namespace="http://ns.saxonica.com/anonymous-type"
name="BOOKS_anonymous_type_1_at_line_14_of_books.xsd"
count="1"/>
<component kind="element" namespace="" name="CATEGORIES" count="1"/>
<component kind="simpleType" namespace="" name="ISBNType" count="6"/>
<component kind="simpleType"
namespace="http://www.w3.org/2001/XMLSchema"
name="string"
count="22"/>
<component kind="complexType"
namespace="http://ns.saxonica.com/anonymous-type"
name="ITEM_anonymous_type_1_at_line_39_of_books.xsd"
count="6"/>
<component kind="simpleType" namespace="" name="weightUnitType" count="6"/>
<component kind="complexType"
namespace="http://ns.saxonica.com/anonymous-type"
name="CATEGORY_anonymous_type_1_at_line_31_of_books.xsd"
count="3"/>
<component kind="simpleType"
namespace="http://www.w3.org/2001/XMLSchema"
name="date"
count="6"/>
<component kind="simpleType"
namespace="http://www.w3.org/2001/XMLSchema"
name="integer"
count="12"/>
<component kind="element" namespace="" name="TITLE" count="6"/>
<component kind="element" namespace="" name="PRICE" count="6"/>
<component kind="element" namespace="" name="WEIGHT" count="6"/>
<component kind="complexType" namespace="" name="dimensionsType" count="6"/>
<component kind="element" namespace="" name="ITEM" count="6"/>
<component kind="simpleType" namespace="" name="lengthUnitType" count="6"/>
<component kind="element" namespace="" name="BOOKS" count="1"/>
</schemaCoverage>
这似乎正是您要找的。
我为 XSLT 3.0 测试套件做了一个类似这样的练习。您可以在此处找到样式表:
https://dvcs.w3.org/hg/xslt30-test/file/24e8b98b044b/tests/misc/catalog/catalog-007.xsl
需要两个输入:
(a) 使用带有 -scmout 选项的 com.saxonica.Validate 生成的 SCM 文件,应用于 schema-for-xslt30。 SCM 文件是编译模式的表示,从 XSLT 分析比原始源模式更容易分析
(b) 测试套件中的非错误样式表集,通过递归搜索测试元数据目录获得。
它提取模式允许的 element-name/attribute-name 对集,然后提取样式表中实际存在的 element-name/attribute-name 对集(在每种情况下都经过过滤,例如仅考虑元素XSLT 命名空间)。然后它比较两个列表,并报告模式允许但测试样式表中不存在的任何对,以及测试样式表中存在但模式不允许的任何对。只有当两个列表都为空时,测试才会通过。