Hi ,
I have two .xml files with contents as below:
demo1.xml
------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<agenda>
<Appointment>
<Id> 7 </Id>
<Date> 20060426 </Date>
<Time> 120000 </Time>
<Subject> test </Subject>
<Description> testttt </Description>
<Place> paris </Place>
<Modtime> 182204 </Modtime>
</Appointment>
<Appointment>
<Id> 8 </Id>
<Date> 20060426 </Date>
<Time> 120000 </Time>
<Subject> whatever </Subject>
<Description> whateverrr </Description>
<Place> where ever </Place>
<Modtime> 182204 </Modtime>
</Appointment>
</agenda>
demo.xml
-----------
<?xml version="1.0" encoding="ISO-8859-1"?>
<agenda>
<Appointment>
<Id> 7 </Id>
<Date> 20060426 </Date>
<Time> 120000 </Time>
<Subject> test </Subject>
<Description> testttt </Description>
<Place> paris </Place>
<Modtime> 182204 </Modtime>
</Appointment>
</agenda>
See from the two files above, Id=7 is common in both .xml files.
I want to select Id=8 which is not present in demo.xml.
So my output should be as below:
<Appointment>
<Id> 8 </Id>
<Date> 20060426 </Date>
<Time> 120000 </Time>
<Subject> whatever </Subject>
<Description> whateverrr </Description>
<Place> where ever </Place>
<Modtime> 182204 </Modtime>
</Appointment>
I tried the below code but I could not arrive at what I need.
string origPath = @"F:\demo.xml";
string inPath = @"F:\demo1.xml";
XElement xmlObject = XElement.Load(origPath);
var xDoc = xmlObject.Descendants("Appointment");
XElement xmlObject1 = XElement.Load(inPath);
var xDoc1 = xmlObject1.Descendants("Appointment");
var notIn = xDoc1.Except(xDoc);
foreach (XElement ele in notIn)
{
richTextBox1.AppendText(ele.ToString() + "\n");
}
When executing the code above I got:
<Appointment>
<Id> 7 </Id>
<Date> 20060426 </Date>
<Time> 120000 </Time>
<Subject> test </Subject>
<Description> testttt </Description>
<Place> paris </Place>
<Modtime> 182204 </Modtime>
</Appointment>
<Appointment>
<Id> 8 </Id>
<Date> 20060426 </Date>
<Time> 120000 </Time>
<Subject> whatever </Subject>
<Description> whateverrr </Description>
<Place> where ever </Place>
<Modtime> 182204 </Modtime>
</Appointment>
But the below code provides me the result what actually I need:
double[] numbers1 = { 2.0, 2.1, 2.2, 2.3, 2.4, 2.5 };
double[] numbers2 = { 2.2 };
IEnumerable<double> onlyInFirstSet = numbers1.Except(numbers2);
foreach (double number in onlyInFirstSet)
richTextBox1.AppendText(number.ToString() +"\n");
The immediate above code provided:
2,2.1,2.3,2.4,2.5
Please let me know what is wrong in my code to fetch distinct elements from xml file?
BR,
Arjun