[英]using xsd:any for extensible schema
Until now, I've been handling extensions by defining a placeholder element that has "name" and "value" attributes as shown in the below example 到目前为止,我一直在通过定义具有“name”和“value”属性的占位符元素来处理扩展 ,如下例所示
<root>
<typed-content>
...
</typed-content>
<extension name="var1" value="val1"/>
<extension name="var2" value="val2"/>
....
</root>
I am now planning to switch to using xsd:any . 我现在打算切换到使用xsd:any 。 I'd appreciate if you can help me choose th best approach
如果你能帮助我选择最佳方法,我将不胜感激
Thank you 谢谢
<xsd:any processContents="strict">
gives people the ability to add extensions to their XML instance documents without changing the original schema . <xsd:any processContents="strict">
使人们能够在不更改原始模式的情况下向其XML实例文档添加扩展。 This is the critical benefit it gives you. <xsd:any>
or not. <xsd:any>
并不重要。 <xsd:any>
very elegantly. <xsd:any>
。 This is understandable, since they have no information about what it could contain, so they'll usually give you an untyped placeholder. <xsd:any>
makes life a bit harder on the programmer, due to the untyped nature of the bindings, but if you need to support arbitrary extension points, this is the way to do it. <xsd:any>
使程序员的生活变得更加困难,但如果你需要支持任意扩展点,这就是这样做的方法。 However, if your extensions are well-defined, and do not change, then it may not be worth the irritation factor. Regarding point 3 关于第3点
Binding tools generally don't handle very elegantly.
绑定工具通常不能非常优雅地处理。 This is understandable, since they have no information about what it could contain, so they'll usually give you an untyped placeholder.
这是可以理解的,因为它们没有关于它可能包含什么的信息,所以它们通常会给你一个无类型的占位符。 It's up the the application code to handle that at runtime.
它是在运行时处理它的应用程序代码。 JAXB is particular (the RI, at least) makes a bit of a fist of it, but it's workable.
JAXB特别(RI,至少)是它的一个拳头,但它是可行的。
This corresponds to the @XmlAnyElement annotation in JAXB. 这对应于JAXB中的@XmlAnyElement批注。 The behaviour is as follows:
行为如下:
@XmlAnyElement - Keep All as DOM Nodes @XmlAnyElement - 将所有内容保存为DOM节点
If you annotate a property with this annotation the corresponding portion of the XML document will be kept as DOM nodes. 如果使用此批注对属性进行批注,则XML文档的相应部分将保留为DOM节点。
@XMLAnyElement(lax=true) - Convert Known Elements to Domain Objects @XMLAnyElement(lax = true) - 将已知元素转换为域对象
By setting lax=true , if JAXB has a root type corresponding to that QName then it will convert that chunk to a domain object. 通过设置lax = true ,如果JAXB具有与该QName对应的根类型,则它将该块转换为域对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.