5

Is there a way to compare two xml nodes in Delphi?

I am using the MSXML parser and loading the xml into an IXmlDOMDocument2. The nodes are stored in an IXmlDOMNode.

I would be ok using Delphi's TXMLDocument if it helps. I do not want to download any third party components.

I just want to compare the structures of the nodes, not the values.

I saw a similar post/utility for Java, but nothing for Delphi.

Thank you!

4

1 回答 1

0

由于您只想比较结构,您可以将节点转换为“完整路径”并将它们作为字符串进行比较。

例如让我们假设树:

树A

Root -> Node1 -> Child1
              -> Child2
     -> Node2

树B

Root -> Node1 -> Child1
     -> Node2

从转换为“完整路径”,您将获得:

树A

Root
Root\Node1
Root\Node1\Child1
Root\Node1\Child2
Root\Node2

树B

Root
Root\Node1
Root\Node1\Child1
Root\Node2

通过迭代完整路径列表,您可以快速检查和比较它们是否存在于另一棵树中。您还可以轻松地找到树上的节点。

于 2014-09-29T23:11:55.573 回答