How compare Two XML Node Structures Delphi

1.1k views Asked by At

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!

1

There are 1 answers

0
mlemanczyk On

Since you want to compare only the structure, you could convert your nodes into 'full paths' and compare them as strings.

E.g. Let's assume the trees:

Tree A

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

Tree B

Root -> Node1 -> Child1
     -> Node2

From the conversion to 'full paths' you'd get:

Tree A

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

Tree B

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

By iterating on the lists of full paths you can quickly check and compare if they exist in the other tree. You can also easily find the nodes on the tree.