Nov 26 2013

Comment by Seth Spearman on How do you use linq to xml to find matching nodes in two different xml files

Ahmed, can you explain how I get the two xml files into your two IEnumberable<Client> variables (orders and orders2)?

Nov 26 2013

Comment by Seth Spearman on Finding Matching Nodes in two XML files using linqpad and linq to xml is finding 0 results

Now, if you would like to help with a more interesting question that would be great. stackoverflow.com/questions/20218821/…

Nov 26 2013

How do you use linq to xml to find matching nodes in two different xml files

I just asked another question here and the answer was spot on.

But that addressed what was essentially a syntax problem. Now I need help with an actual resolution.

This is the same code from the previou question (fixed up and with stuff added).

XElement FILE1 = XElement.Load (@"..\FILE1.XML");
XElement FILE2 = XElement.Load (@"..\FILE2.XML");

var orders = from file1 in FILE1.Descendants("Players").Elements("Player")
                        select new {
                            name=new {
                                clientID=ulm.Element("ClientID").Value,
                                firstName=file1.Element("FirstName").Value,
                                lastName=file1.Element("LastName").Value
                            }                           
                        };

var orders2 = 
             from file2 in FILE2.Descendants("Players").Elements("Player")
                        select new {
                            name=new {
                                clientID=ulm.Element("ClientID").Value,
                                firstName=file2.Element("FirstName").Value,
                                lastName=file2.Element("LastName").Value
                            }                           
                        };

var matchingResults = from i in orders from j in orders2 where (i.name.firstName==j.name.firstName && i.name.lastName==j.name.lastName)
                            select i;
matchingResults.Dump()     

To make it interesting I have added a ClientID to each sequence result before trying to match them up.

What I need is to know does a Player node from order EXISTS in a player node from orders2. Or does it NOT EXIST? Ideally I would also be able to CHOOSE the selection criteria for the NOT EXISTS/EXISTS check. (LastName, or FirstName && LastName, or ClientID only, etc.)

I have NO IDEA how to go about this. Thanks for your help.

Nov 26 2013

Comment by Seth Spearman on Finding Matching Nodes in two XML files using linqpad and linq to xml is finding 0 results

That was it...you da man.
Nov 25 2013

Finding Matching Nodes in two XML files using linqpad and linq to xml is finding 0 results

I have two XML files with the same schema/structure but with different data. I am trying to use Linqpad (Linq to XML) to find the differences between the two files. Here is my code...
XElement FILE1 = XElement.Load (@"..\FILE1.XML");
XElement FILE2 = XElement.Load (@"..\FILE2.XML");

var orders = from file1 in FILE1.Descendants("Players").Elements("Player")
                        select new {
                            name=new {
                                firstName=file1.Element("FirstName"),
                                lastName=file1.Element("LastName")
                            }                           
                        };

var orders2 = 
             from file2 in FILE2.Descendants("Players").Elements("Player")
                        select new {
                            name=new {
                                firstName=file2.Element("FirstName"),
                                lastName=file2.Element("LastName")
                            }                           
                        };

var matchingResults = from i in orders from j in orders2 where (i.name.firstName==j.name.firstName && i.name.lastName==j.name.lastName)
                            select i;
matchingResults.Dump()                          
The last Dump() is returning 0 results. I KNOW there is matching data in the two files. EDIT I forgot to mention that if I dump the results of each of the queries I get results (that are very similar) for both sequences. I have also tried the approach shown here...
Compare two xml and print the difference using LINQ (which combines the files into one sequence and then does the compare) but I am geting the same result...0 results. That approach also seems to create a cartesian product on the first orders sequence. All I want is to find matching or missing nodes from the files. What am I missing here?
Nov 18 2013

Comment by Seth Spearman on Weird behavior when opening web project in Visual Studio 2012

In the end...this is what fixed it for me. Thanks.

Nov 11 2013

Regular Expression for Finding Email Addresses (that works with Notepad++)

^.*(\<[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z][A-Za-z][A-Za-z]?[A-Za-z]?\>).*$ Today I cleared out an SMTP log using notepad++ so that it only contained email addresses.  Here’s how… CTRL-H.  Change search mode to regular expressions.  Paste the above RegEx in the Find What box. In the Replace with box put \1.  Click Replace All.  That won’t clear the lines that don’t have an email address.  To remove those do this… CTRL-F… click the Mark tab of the Find dialog.  Click the Bookmark Line checkbox.  Paste the above RegEx into the Find What: box.  Click Mark All. In the Search Menu choose Bookmarks, Remove unmarked lines.