是否有任何框架/技术支持将 XML 递归地嵌入到 XML 中?

发布于 2024-11-29 16:42:05 字数 361 浏览 6 评论 0原文

假设我有一组任意 XML,我想将它们递归地嵌入到彼此中。有什么技术或框架可以帮助解决这个问题吗?我正在寻找在 XML 中添加、删除和搜索 XML 的东西。

编辑

有人从我的问题中删除了递归标签。我想我没有说清楚。让我们想象一下 XML 表示相互引用的数据结构实例。有处理这个问题的技术/框架吗?

编辑 II

有人声称我不是在谈论递归,最多只是在谈论循环引用。我并不排除让一个数据结构引用自身的可能性(通过实例或定义,这并不重要)。可以这么说,我的意思确实是递归,就像分形一样,所以请停止删除我的标签。

Let assume I have a set of arbitrary XML's that I would like to embed into each other recursively. Is there any technology or framework helping with this? I am looking for something adding, removing and searching XML's within XML's.

EDIT

Someone removed the recursion tag from my question. I guess I am not making myself clear. Let's imagine XML's represent data structures instances referring each other. Is there a technology/framework handling this?

EDIT II

Someone claims I am not talking about recursion, but about circular references at best. I am not excluding the possibility of having one data structure referencing itself (by instance or by definition, it does not matter). I DO mean recursive as in fractal so to speak, so please stop removing my tag.

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

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

发布评论

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

评论(4

你是我的挚爱i 2024-12-06 16:42:05

不,标准 XML 中不是开箱即用的。基本上,您需要有一个记录最终 XML 文档中元素之间链接的机制,然后有一个精明的编组和解组技术来处理引用。实际上,这是一个对象序列化到 XML 的问题。

例如,如果没有它,如果您尝试保存循环列表,则最终会出现无限循环,因为尾部元素返回到头元素并继续写入。参考资料可以帮你解决这个问题。

我相信 XStream 会开箱即用地为您完成此操作(如果您使用 Java,但您没有提及这一点)。

No, not out of the box in standard XML. Basically you need to have a mechanism of recording linkage between elements in the final XML document, and then have a savvy marshalling and demarshalling tech to handle the references. This is an object serialization to XML issue, effectively.

Without it, for example, if you were to try and save a circular list, you'd end up having an infinite loop as the tail element returns to the head element and keeps writing. References fix that issue for you.

I believe XStream will do this for you out of the box (if you're in Java, but you don't mention that).

情归归情 2024-12-06 16:42:05

将一个 xml 文档嵌入到另一个 xml 文档中的正确方法是使用名称空间来区分内容。

有时人们对内部 xml 进行实体编码并将其嵌入为字符串,但这是一件非常糟糕的事情。不要这样做。

The correct way of embedding one xml document in another is to use namespaces to differentiate the content.

Sometimes people entity-encode the inner xml and embed it as a string, but that's a really bad thing to do. Don't do it.

栀子花开つ 2024-12-06 16:42:05

XML 中的递归是通过配对 id 和 idref 属性来处理的。如果您希望 XML 文档的一个部分引用另一部分,请在您引用的部分上放置一个 id 属性,并在引用者上放置一个 idref 属性。

据我所知,没有解析器会自动遍历这些属性,您需要手动执行。

Recursion in XML is handled with pairing id and idref attributes. If you want one part of an XML document to refer to another part, place an id attribute on the part you're referring to, and an idref attribute on the referrer.

As far as I know no parsers will traverse these attributes automatically, you need to do it manually.

情深已缘浅 2024-12-06 16:42:05

XInclude 怎么样?例如 XOMXerces 支持此扩展。

What about XInclude? E.g. XOM and Xerces support this extension.

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