Xerces:如何合并重复节点?
我的问题是这样的:
如果我有以下 XML:
<root>
<alpha one="start">
<in>1</in>
</alpha>
</root>
然后我将添加以下路径:
<root><alpha one="start"><out>2</out></alpha></root>
这导致
<root>
<alpha one="start">
<in>1</in>
</alpha>
</root>
<root>
<alpha one="start">
<out>2</out>
</alpha>
</root>
我希望能够将其转换为:
<root>
<alpha one="start">
<in>1</in>
<out>2</out>
</alpha>
</root>
除了自己实现之外(今天不想重新发明轮子), Xerces (2.8,C++) 有没有具体的方法来做到这一点?
如果是,那么节点合并在 DOMDocuments 生命周期的哪个点完成? 每次插入时? 在撰写文件时,明确要求?
谢谢。
My question is this:
If I have the following XML:
<root>
<alpha one="start">
<in>1</in>
</alpha>
</root>
and then I'll add the following path:
<root><alpha one="start"><out>2</out></alpha></root>
which results in
<root>
<alpha one="start">
<in>1</in>
</alpha>
</root>
<root>
<alpha one="start">
<out>2</out>
</alpha>
</root>
I want to be able to convert it into this:
<root>
<alpha one="start">
<in>1</in>
<out>2</out>
</alpha>
</root>
Besides implementing it myself (don't feel like reinventing the wheel today),
is there a specific way in Xerces (2.8,C++) to do it?
If so, at which point of the DOMDocuments life is the node merging done? at each insertion? at the writing of the document, explicitly on demand?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用 xalan,则可以使用 xpath 来查找元素并直接插入到正确的元素中。
以下代码可能会很慢,但会返回属性“one”设置为“start”的所有“root”元素。
使用完整路径可能会更好
,或者如果您已经有父元素工作相对
我认为获得基本概念 维基百科上的 xpath。
If you use xalan its possible to use an xpath to find the element and directly insert into the correc one.
The following code may be slow but returns all "root" elments with the attribute "one" set to "start".
It is probably better to use the full path
or if you already have the parent element work relative
I think to get the basic concepts xpath on wikipedia.
如果您知道存在各种不同标签的容器标签的名称,这不是一分钟的任务吗?
在您的示例中,获取所有 XML 文档中指向
alpha
标记的指针,并将所有内容放入新文档的 alpha 中(如果它们尚未存在)。这并不像重新发明轮子那么糟糕。 我不熟悉 Xerces,但对于 libxml++,我认为这是一项简单的任务。
Isn't it just a one minute task if you know the names of the container tag where various different tags are present?
In your example, get a pointer to the
alpha
tag in all the XML documents and put the contents of all of them into a new document's alpha if they're not present there already.This isn't as bad as reinventing the wheel. I'm not familiar with Xerces, but with libxml++, I would call this an easy task.