简体   繁体   English

使用xsd:any用于可扩展模式

[英]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 如果你能帮助我选择最佳方法,我将不胜感激

  1. What is the value add of xsd:any over my previous approach if I specify processContents="strict" 如果我指定processContents =“strict”,xsd:any的值是什么超过我以前的方法
  2. Can a EAI/ESB tool/library execute XPATH expressions against the arbitrary elements I return EAI / ESB工具/库是否可以针对我返回的任意元素执行XPATH表达式
  3. I see various binding tools treating this separately while generating the binding code. 我看到各种绑定工具在生成绑定代码时单独处理它。 Is this this the same case if I include a namespace="http://mynamespace" and provide the schema for the "http://mynamespace" during code gen time? 如果我在代码生成时间内包含namespace =“http:// mynamespace”并提供“http:// mynamespace”的架构,这是否相同?
  4. Is this WS-I compliant? 这是WS-I兼容的吗?
  5. Are there any gotchas that I am missing? 我有什么陷阱吗?

Thank you 谢谢

  1. Using <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. 这是它给你带来的重要好处。
  2. Yes. 是。 tools than manipulate the instances don't care what the schema looks like, it's the instance documents they look at. 工具比操纵实例不关心模式是什么样的,它是他们看到的实例文档。 To them, it doesn't really matter if you use <xsd:any> or not. 对他们来说,如果你使用<xsd:any>并不重要。
  3. Binding tools generally don't handle <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. 这是可以理解的,因为它们没有关于它可能包含什么的信息,所以它们通常会给你一个无类型的占位符。 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,至少)是它的一个拳头,但它是可行的。
  4. Yes. 是。 It's perfectly good XML Schema practice, and all valid XML Schema are supported by WS-I 这是非常好的XML Schema实践,WS-I支持所有有效的XML Schema
  5. <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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM