如何重新排序节点元素,使它们匹配xsd:sequence顺序? [英] How to reorder node elements such that they match an xsd:sequence order?

查看:254
本文介绍了如何重新排序节点元素,使它们匹配xsd:sequence顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法重新排序Node对象中的元素,使它们匹配 xsd:sequence 顺序?我已经阅读了 Node.normalize 的文档,但它似乎没有执行该功能。还有其他什么可以做吗?

Is there any way to reorder elements in a Node objects such that they match an xsd:sequence order? I've read through the docs for Node.normalize, but it doesn't seem to perform that function. Is there something else that can be done?

我相信它可以用XSLT完成,但这听起来像是一个过于复杂的使用XSLT的解决方案,还有一个特殊的解决方案 java-xlst 解析器执行操作而不是在java中使用本机。

I believe that it can be done with XSLT, but it would sound like an overly convoluted solution to use XSLT, and a special java-xlst parser to perform the manipulation as opposed to having something native in java.

或者我是否真的需要编写一个复杂的函数来为我处理?

Or would I actually need to code a complex function to do the processing for me?

推荐答案

如果我正确地读了你的问题,你想要的是一个根据外部XSD重新排列节点的神奇(如简单)方式,而不是使用某些XML API移动节点的方法。

If I read your question correctly, what you want is rather a "magical" (as in a simple) way of getting nodes re-arranged according to an external XSD, as opposed to a way to move nodes around using some XML API.

如果是,那么我不知道任何API提供了实现这种事情的通用方法。考虑到XSD能够描述的内容模型的复杂性,它也不是一个简单的编程。

If true, then I am not aware of any API that provides a generic way to achieve such a thing. It is also not a trivial piece of programming, given the complexity of the content models XSD is able to describe.

在非常简单的情况下,它也几乎不可能解决。想想这个非常简单的例子:想象一个由两个选择组成的内容模型,i)序列a - b - c,ii)序列b - c - a。 XML内容按顺序c-b-a(根据您的要求,您希望获取无效的XML,并使其有效)。在这个例子中,这是正确的方法吗?

It is also, under very simple circumstances, virtually impossible to solve. Think of this very simple example: imagine a content model made up of two choices, i) sequence a - b - c , ii) sequence b - c - a. The XML content comes in the order c - b - a (as per your requirement, you want to take in invalid XML, and make it valid). In this example, which is the right way to do it?

当然,我不是说这是你的情景。我只是想指出为什么没有人,据我所知,已经找到了解决这个问题的方法。

Of course, I am not saying this is your scenario. I am simply trying to point out why no one, as far as I know, has come up with a solution to such a problem.

如果你的内容模型在序列之下它是相当微不足道的,因此无论XML到达的顺序如何,或者如果XML内容始终以已知但错误的方式出现,都允许以明确的方式解决它,那么您必须使用您的首选方法对其进行编码处理XML操作的方法 - 但我建议,不要试图让它变得通用,它只是在兔子洞里走下去;)....

If your content model under the sequence is rather trivial, thus allowing for an unambiguous way of solving it irrespective of the sequence in which your XML arrives, or if the XML content comes in a known, but wrong way, all the time, then you have to code it using your preferred approach to XML manipulation - but I would suggest, don't try to make it generic, it is just going down the rabbit hole ;)....

这篇关于如何重新排序节点元素,使它们匹配xsd:sequence顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆