[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

GetXPath from XmlNode

Posted on 2010-09-20
4
Medium Priority
?
382 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 1000 total points
ID: 33719399
0
 
LVL 16

Accepted Solution

by:
kris_per earned 1000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

650 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