Solved

GetXPath from XmlNode

Posted on 2010-09-20
4
380 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

687 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