如何在 processContents=lax 中指定外部模式
我有一个通用模式,定义了这样的部分:
<xs:element name="detail">
<xs:annotation>
<xs:documentation>
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:anyAttribute processContents="skip"/>
</xs:complexType>
</xs:element>
我一天中的大部分时间都在阅读这些内容,但似乎仍然无法理解如何深入了解可以在其中找到的字段详细信息元素下的实际 xml 文档。
我知道它可能看起来像这样:
<detail>
<drawing>
<name="test"/>
</drawing>
</detail>
或者
<detail>
<icon>
<icon_name="testIcon"/>
<icon_image="iconImage.jpg"/>
</icon>
</detail>
xmlbeans 没有办法知道详细信息元素中的内容,因为它是通配符,因此它没有为我提供深入研究这些元素的方法。 xmlbeans 站点表明我修改了已读入的文档以将通配符元素向上移动一个级别,但这似乎并不明确。 我还可以修改架构以对可能存在于我的特定代码中的元素进行元素引用。对此有何想法?
I have a generic schema that defines a section like this:
<xs:element name="detail">
<xs:annotation>
<xs:documentation>
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:anyAttribute processContents="skip"/>
</xs:complexType>
</xs:element>
I've been reading up on this stuff for most of the day, but still can't seem to wrap my head around how to get down to the fields that would be found in the actual xml document under the detail element.
I know that it could look like this:
<detail>
<drawing>
<name="test"/>
</drawing>
</detail>
or
<detail>
<icon>
<icon_name="testIcon"/>
<icon_image="iconImage.jpg"/>
</icon>
</detail>
xmlbeans doesn't have a way of knowing what is going into the details element since it is a wildcard, so it does not provide me a way of diving into those elements. the xmlbeans site was indicating that i modify the document i have read in to move the wildcard elements up a level, but that doesn't seem cut and dry.
I could also modify the schema to do an element ref on the elements that could be there for my particular code. Thoughts on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于详细信息元素可以包含任何有效的 XML,因此您只能使用某种访问内容的通用方法(XPath、DOM 遍历或类似方法),或者专门尝试将每个子元素与特定模式匹配(最好使用唯一的命名空间)。然后,与已知模式匹配的子项可以被输入到您最喜欢的库中,该库可以从 XML 生成对象。
正如您所说,另一种选择可能是指定架构中的每个有效子类型(出于可扩展性的目的,可以选择在底部使用通配符)。
Since the detail element can contain any valid XML you are limited to either using some generic way of accessing the contents (XPath, DOM traversal or similar) or by specifically trying to match each child to a specfic schema (preferrably by using unique namespaces). Children matching a known schema could then be fed to your favourite library that generates objects out of XML.
Another option could, as you say, be to specify each valid child type in the schema (optionally with a wildcard on the bottom for extensibility purposes).