Xml 报告对应架构的所有未使用元素(+;属性)
在这个主题中,我想问的脑细胞比我自己能提供的要多得多。我想根据实际XML实例中已使用/未使用的元素(仅限于单个名称空间),重构我的XSD(v1.0)。让我们建立一个小的场景: 我只有对应架构的有效XML文档:Xml 报告对应架构的所有未使用元素(+;属性),xml,xslt,xsd,saxon,xslt-3.0,Xml,Xslt,Xsd,Saxon,Xslt 3.0,在这个主题中,我想问的脑细胞比我自己能提供的要多得多。我想根据实际XML实例中已使用/未使用的元素(仅限于单个名称空间),重构我的XSD(v1.0)。让我们建立一个小的场景: 我只有对应架构的有效XML文档: <body> <h1>Heading 1</h1> <p>paragraph</p> <p><bold>bold</bold>paragraph<italic>
<body>
<h1>Heading 1</h1>
<p>paragraph</p>
<p><bold>bold</bold>paragraph<italic>italic</italic></p>
</body>
标题1
段落
粗体段落斜体
要验证的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可用]),报告哪些元素(标记+属性)在XML实例中未使用,但在XSD中可能使用
简化的伪TODO/从头开始:
- 在my XSD中搜索所有
(属性在report v2.0中跟随)//xs:element[@name]
- 在我的XML中搜索所有
*
- “比较”它
xsl:map
?存储路径[/body/h1
,/body/p
]并比较这些路径?(棘手的是:从模式中获取正确的路径,处理所有定义方式,如xs:group ref=“…”
或通过complexTypes
等)
[插件:也许我必须将其扩展到XML中祖先元素的上下文中
区分//p/underline
和//span/underline
]
请开明地写下你的想法。我不要求完整的功能代码代码>查看并获取节点上Saxon EE中的模式类型信息,希望这是一种将实例与模式进行比较的方法。我从来没用过,所以我不知道你能走多远,我相信,如果您在问题中添加了-stats:report.xml,那么Michael Kay将在适当的时候为您提供一些更好的见解。您的帖子提醒我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测试套件做了类似的练习。您可以在此处找到样式表:
它需要两个输入:
(a) 使用com.saxonica.Validate和-scmout选项生成的SCM文件,应用于schema-for-xslt30。SCM文件是编译模式的一种表示形式,与原始源模式相比,它更容易从XSLT进行分析
(b) 测试套件中的一组无错误样式表,通过递归搜索测试元数据目录获得
它提取由模式允许的元素名称/属性名称对集合,然后提取在样式表中实际存在的元素名称/属性名称对集合(在每种情况下都被过滤,例如只考虑XSLT命名空间中的元素)。然后,它比较这两个列表,并报告测试样式表中不存在的模式允许的任何对,以及模式不允许的测试样式表中存在的任何对。只有当两个列表都为空时,测试才会通过
谢谢你,加上了强大的凯博士的标签。