使用 XSD 过滤 XML [英] Filter XML with XSD

查看:26
本文介绍了使用 XSD 过滤 XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 XML 及其 XSD 文件.所以,XSD 说明哪些是 XML 的必需字段,我只需要提取它们 - 基本上是一个只有必需字段的新 XML(坦率地说,我需要具有 minOccurs='1' 在 XSD 中).我知道为此我需要 XSLT,但有什么方法/应用程序可以生成 XSLT,它只会提取 XSD 文件中具有 minOccurs='1' 的节点.

I've got an XML and its XSD file. So, the XSD says which are the required fields of the XML and I need to extract just them - basically a new XML with only the required fields (frankly, I need the nodes which have minOccurs='1' in the XSD). I am aware that I need XSLT for this but is there any way/application to generate an XSLT which will only extract the nodes that have minOccurs='1' in the XSD file.

推荐答案

对于任意模式执行此操作很棘手.例如,您可能会遇到像 (A B A? B) 这样的内容模型,其中第一个 A 是必需的,第二个是可选的.或者,当然,您可能会遇到 minOccurs="2".我不认为有任何捷径;这是一个重要的项目.但是,如果您准备软化要求,例如仅处理以特定方式编写的模式或避免笨拙的结构,那么它可能会更容易.

It's tricky to do this for an arbitrary schema. For example, you might encounter a content model like (A B A? B) where the first A is mandatory and the second is optional. Or, of course, you might encounter minOccurs="2". I don't think there are any short-cuts; it's a significant project. However, if you are prepared to soften the requirement, for example to only handle schemas written in a particular way or that avoid awkward constructs, then it could be rather easier.

这篇关于使用 XSD 过滤 XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆