【发布时间】:2016-08-17 17:21:49
【问题描述】:
我目前正在重构一批 XML 文档,该过程涉及将 xml 重构为新修订的 DTD Schema。由于使用了新的 DTD,许多最初使用的元素要么被重新利用、重新嵌套在其他元素中,要么被完全删除。 下面的示例是针对 DTD 进行验证时的无效 xml 文档。为了加快重构 XML 的过程,我认为 XQuery 脚本或 XSLT 转换可能会有所帮助。但是,我对这两种方法的经验都为零,而且对 XML 还是很陌生。有人可以向我解释一下 XQuery、XSLT 还是 Xpath 中哪种语言在重构这些文档时最相关。
无效的 XML:
<PartsDoc foo=”” baa=”” bar=”” revno=”” docno=”” >
<PartsDocInfo>
<repairlvl level=”shop” />
<title id=”123”> Foo Electrical Control Box </title>
</PartsDocInfo>
<Parts.Category>
<figure id=”123” >
<title id=”123”> Control Box Panels </title>
<subfig id=”123”>
<graphic img=”foo.jpg” />
</subfig>
<!- - everything above is valid, the below portion is not - ->
<parts.item>
<callout id=”123” config=”123” label=”1” />
<mrs service=”shop” sc=”” mc=”” rec=”” />
<nsn niin=”00-123-4567”> 4444-00-123-5467</nsn>
<cageno>12345</cageno>
<partno>12345</partno>
<name/>
<desc id=”123” > Bolt 1/2inch </desc>
<qty>4</qty>
<parts.item>
</parts.category>
期望的输出:
<PartsDoc foo=”” baa=”” bar=”” revno=”” docno=”” >
<PartsDocInfo>
<repairlvl level=”shop” />
<title id=”123”> Foo Electrical Control Box </title>
</PartsDocInfo>
<Parts.Category>
<figure id=”123” >
<title id=”123”> Control Box Panels </title>
<subfig id=”123”>
<graphic img=”foo.jpg” />
</subfig>
<parts.item>
<callout id=”123” config=”123” label=”1” />
<qty>4</qty>
<mrs service=”shop” sc=”” mc=”” rec=”” />
<nsn>
<fsc>4444</fsc>
<niin>00-12-5467
</nsn>
<partno>12345</partno>
<cageno>12345</cageno>
<name/>
<desc id=”123” > Bolt 1/2inch </desc>
<parts.item>
</parts.category>
*注意
<qty>已移动 *注意<partno>已移动 *注意<nsn>不包括内容已排序的子元素
此外,某些实例包含一个 <uoc> 元素,该元素作为子元素嵌套在 <desc> 中。
<desc>
bolt 1/2inch
<uoc>XYZ</uoc>
</desc>
<uoc> 实际上应该在 <callout> 之后和之前
<qty>
非常感谢任何有关 XSLT 样式表或 XQuery 脚本的帮助,并简要说明为什么选择一种语言而不是另一种语言。我目前正在使用 Oxygen 17 XML 编辑器
【问题讨论】:
标签: xml xpath xquery oxygenxml