Solved

GetXPath from XmlNode

Posted on 2010-09-20
4
368 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 74

Assisted Solution

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

Accepted Solution

by:
kris_per earned 250 total points
Comment Utility

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
Comment Utility
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
Comment Utility
good solutions!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now