Solved

GetXPath from XmlNode

Posted on 2010-09-20
4
377 Views
Last Modified: 2012-05-10
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?

0
Comment
Question by:breezback
4 Comments
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 250 total points
ID: 33719399
0
 
LVL 16

Accepted Solution

by:
kris_per earned 250 total points
ID: 33719601

Following link has a code that compares two xml and instead of removing the nodes from xml1 (as in your case), it adds the extra nodes to xml1...It also has a method to get the xpath from xmlnode...I hope it gives you the idea you need.

=> http://forums.devx.com/showthread.php?t=168067
0
 
LVL 1

Expert Comment

by:amr-it
ID: 33719899
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
0
 

Author Closing Comment

by:breezback
ID: 33760224
good solutions!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question