Link to home
Start Free TrialLog in
Avatar of breezback
breezbackFlag for Israel

asked on

GetXPath from XmlNode

I'm scanning an xml and I would like to compare the nodes between 2 xmls.
Let's say 1=xmlInput and 2=xmlReference.

I'm scanning the xmlInput recursively and I would like to check with xPath if it exists in the xmlReference.

for example: xmlInput
<root>
<children>
<child id='A' value='10'>
<child id='B' value='XXX'>
</children>
</root>

and xmlReference:
<root>
<children>
<child id='A' value='0'>
</children>
</root>

It would mean that XmlNode (child[id=B]) is not found in reference and I would like to remove it from xmlInput so the final xmlInput. It will look like:
<root>
<children>
<child id='A' value='10'>
</children>
</root>

Currently what I'm looking for is a method to return XPath from XmlNode. Any ideas?

SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of amr-it
amr-it

An alternative would be using LINQ comparing all your child-nodes with a LINQ-query if you are familiar with SQL.

MSDN:
http://msdn.microsoft.com/en-us/library/bb425822.aspx

HookedOnLINQ also have some good LINQ examples:
http://www.hookedonlinq.com/LINQtoXML5MinuteOverview.ashx

When you have done your comparison you can write a new input or just store it directly to a database.

Cheers
Avatar of breezback

ASKER

good solutions!