使用 xsd:any 实现可扩展模式

发布于 2024-10-16 01:15:17 字数 660 浏览 6 评论 0原文

到目前为止,我一直通过定义具有“名称”和“值”属性的占位符元素来处理扩展,如下面的示例所示,

<root>
   <typed-content>
      ...
   </typed-content>
   <extension name="var1" value="val1"/>
   <extension name="var2" value="val2"/>
....
</root>

我现在计划切换到使用xsd:任何。如果您能帮助我选择最佳方法,我将不胜感激

  1. 如果我指定 processContents="strict",则 xsd:any 相对于我以前的方法有什么附加值
  2. EAI/ESB 工具/库可以针对任意元素执行 XPATH 表达式吗? return
  3. 我看到各种绑定工具在生成绑定代码时单独处理此问题。如果我包含 namespace="http://mynamespace" 并在代码生成期间提供“http://mynamespace”的架构,情况是否相同?
  4. 这符合 WS-I 标准吗?
  5. 我有什么遗漏的地方吗?

谢谢

Until now, I've been handling extensions by defining a placeholder element that has "name" and "value" attributes as shown in the below example

<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. 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"
  2. Can a EAI/ESB tool/library execute XPATH expressions against the arbitrary elements I return
  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?
  4. Is this WS-I compliant?
  5. Are there any gotchas that I am missing?

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

节枝 2024-10-23 01:15:17
  1. 使用 使人们能够在不更改原始架构的情况下向其 XML 实例文档添加扩展。这是它为您带来的关键优势。
  2. 是的。操作实例的工具并不关心架构是什么样的,而是它们查看的实例文档。对于他们来说,是否使用 并不重要。
  3. 绑定工具通常不能非常优雅地处理。这是可以理解的,因为他们没有关于它可能包含什么的信息,所以他们通常会给你一个无类型的占位符。由应用程序代码在运行时处理该问题。 JAXB 很特殊(至少是 RI),但它是可行的。
  4. 是的。 支持所有有效的 XML 模式,
  5. 这是非常好的 XML 模式实践,并且 WS-I 由于绑定的非类型化性质,这使得程序员的生活变得更加困难,但是如果您需要支持任意扩展点,可以这样做。但是,如果您的扩展定义明确并且不改变,那么可能不值得这么刺激。
  1. Using <xsd:any processContents="strict"> gives people the ability to add extensions to their XML instance documents without changing the original schema. 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.
  3. Binding tools generally don't handle <xsd:any> 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.
  4. Yes. It's perfectly good XML Schema practice, and all valid XML Schema are supported by WS-I
  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. However, if your extensions are well-defined, and do not change, then it may not be worth the irritation factor.
川水往事 2024-10-23 01:15:17

关于第3点

绑定工具一般不处理
非常优雅。这是
可以理解,因为他们没有
有关它可以做什么的信息
包含,所以他们通常会给你
无类型占位符。这是在
处理该问题的应用程序代码
运行时。 JAXB 是特殊的(RI、
至少)做了一点拳头,
但它是可行的。

这对应于 @XmlAnyElement JAXB 中的注释。行为如下:

@XmlAnyElement - 全部保留为 DOM 节点

如果使用此注释对属性进行注释,则 XML 文档的相应部分将保留为 DOM 节点。

@XMLAnyElement(lax=true) - 将已知元素转换为域对象

通过设置 lax=true,如果 JAXB 具有与该 QName 对应的根类型,那么它将转换该块到域对象。

Regarding point 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.

This corresponds to the @XmlAnyElement annotation in JAXB. The behaviour is as follows:

@XmlAnyElement - Keep All as DOM Nodes

If you annotate a property with this annotation the corresponding portion of the XML document will be kept as DOM nodes.

@XMLAnyElement(lax=true) - Convert Known Elements to Domain Objects

By setting lax=true, if JAXB has a root type corresponding to that QName then it will convert that chunk to a domain object.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文