Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, September 11, 2018 5:02 PM
Hello experts,
i am kinda new to thisstuff, i wanted to know how to compare two xml files using xmlunit or xslt and display another xml file only with the differences in the xml file:
SourceXML:
<?xml version="1.0" encoding="utf-8"?>
<CUSTOMSEDI xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.dell.com/dbi/fsl/compliance/v1_0">
<ASNNUM>SXMSEO180814001D</ASNNUM>
<ORDERS>
<ORDER>
<CUSNAME>743828553</CUSNAME>
<ORDERNUM>979793524</ORDERNUM>
<CITY />
<TIES>
<TIE>
<TIENUMBER>1</TIENUMBER>
<TIEQTY>1</TIEQTY>
<ITEMS>
<ITEM>
<ITEMNUMBER>KF3P2</ITEMNUMBER>
<ITEMQTY>1</ITEMQTY>
<PRICE>8.27</PRICE>
</ITEM>
<ITEM>
<ITEMNUMBER>60RD2</ITEMNUMBER>
<ITEMQTY>1</ITEMQTY>
<PRICE>8.27</PRICE>
</ITEM>
</ITEMS>
</TIE>
</TIES>
</ORDER>
<ORDER>
<CUSNAME>743828552</CUSNAME>
<ORDERNUM>979794834</ORDERNUM>
<CITY />
<TIES>
<TIE>
<TIENUMBER>1</TIENUMBER>
<TIEQTY>1</TIEQTY>
<ITEMS>
<ITEM>
<ITEMNUMBER>K850M</ITEMNUMBER>
<ITEMQTY>1</ITEMQTY>
<PRICE>1.54</PRICE>
</ITEM>
<ITEM>
<ITEMNUMBER>T732H</ITEMNUMBER>
<ITEMQTY>1</ITEMQTY>
<PRICE>1.54</PRICE>
</ITEM>
</ITEMS>
</TIE>
</TIES>
</ORDER>
</ORDERS>
XML2:
<?xml version="1.0" encoding="utf-8"?>
<CUSTOMSEDI xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.dell.com/dbi/fsl/compliance/v1_0">
<ASNNUM>SXMSEO180814001D</ASNNUM>
<ORDERS>
<ORDER>
<CUSID>744400014</CUSID>
<ORDERNUM>979794834</ORDERNUM>
<TIES>
<TIE>
<TIENUMBER>1</TIENUMBER>
<TIEQTY>1</TIEQTY>
<ITEMS>
<ITEM>
<ITEMNUMBER>T732H</ITEMNUMBER>
<ITEMQTY>1</ITEMQTY>
<PRICE>1.54</PRICE>
</ITEM>
<ITEM>
<ITEMNUMBER>K850M</ITEMNUMBER>
<ITEMQTY>1</ITEMQTY>
<PRICE>1.54</PRICE>
</ITEM>
</ITEMS>
</TIE>
</TIES>
</ORDER>
<ORDER>
<CUSID>743138972</CUSID>
<CUSADDRESS>KLS Tokyo Terminal3-2-31 Yashio, Shinagawa, TokyoJapan</CUSADDRESS>
<ORDERNUM>979793524</ORDERNUM>
<TIES>
<TIE>
<TIENUMBER>1</TIENUMBER>
<TIEQTY>1</TIEQTY>
<ITEMS>
<ITEM>
<ITEMNUMBER>60RD2</ITEMNUMBER>
<ITEMQTY>1</ITEMQTY>
<PRICE>8.27</PRICE>
</ITEM>
<ITEM>
<ITEMNUMBER>KF3P2</ITEMNUMBER>
<ITEMQTY>25</ITEMQTY>
<PRICE>8.27</PRICE>
</ITEM>
</ITEMS>
</TIE>
</TIES>
</ORDER>
</ORDERS>
Thanks,
ram
All replies (8)
Wednesday, September 12, 2018 7:47 AM
How big are your XML files? The fastest approach to implement (for smaller files): Deserialize them and compare the objects (LINQ). Depending on the used schema, this can be speed up by not fully deserializing them depending on your concrete use-case.
So, what is your use-case?
Wednesday, September 12, 2018 7:51 AM
Hi coolram4u,
Thank you for posting here.
For your question, I suggest to use xml diff. You could download the source file from the MSDN document. Microsoft provide a simple example to get the difference.
https://msdn.microsoft.com/en-us/library/aa302295.aspx?f=255&MSPPError=-2147217396
Based on my test, change the code below will make the .exe works well.
Browse.cs
change:
private void Browser_Load(object sender, System.EventArgs e)
{
hc.Size = this.Size;
string currPath = AppDomain.CurrentDomain.BaseDirectory ;
hc.Navigate( "file:///" + currPath + navigateTo );
hc.Show();
}
to:
private void Browser_Load(object sender, System.EventArgs e)
{
hc.Size = this.Size;
hc.Navigate( "file:///" + navigateTo );
hc.Show();
}
Based on my test, there is something wrong with your xml file. I use a simple xml for reference. Here is the difference for the simple xml file.
file1.xml
<Car>
<Name> Taurus </Name>
<Color> White </Color>
</Car>
file2.xml
<Car>
<Name> Taurus </Name>
<Color1> White1 </Color1>
</Car>
Best Regards,
Wendy
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].
Wednesday, September 12, 2018 8:59 AM
Firstly thanks a lot for your reply Stefan. My Xml files are little larger which might have max of 1000 - 2000 lines and i need to verify all the item sections based on the unique order number and compare with the second xml as shown in the above xml files. As iam new to this field could you please provide me some code which could be a great help for me.
ram
Wednesday, September 12, 2018 9:01 AM
Thanks a lot Wendy. I already tried this tool and it is showing few of the outputs wrongly when iam trying to compare large xml files. So would like to know of there is possibility to implement using XSLT where i need to compare Item sections of both the xml files.
ram
Thursday, September 13, 2018 7:17 AM
Hi coolram4u,
The tool is so nice. I test your xml file. Your xml file is not complete. You did not close the tag.
I fix the error for your xml file.
XML1
<?xml version="1.0" encoding="UTF-8"?>
<CUSTOMSEDI xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.dell.com/dbi/fsl/compliance/v1_0">
<ASNNUM>SXMSEO180814001D</ASNNUM>
<ORDERS>
<ORDER>
<CUSNAME>743828553</CUSNAME>
<ORDERNUM>979793524</ORDERNUM>
<CITY />
<TIES>
<TIE>
<TIENUMBER>1</TIENUMBER>
<TIEQTY>1</TIEQTY>
<ITEMS>
<ITEM>
<ITEMNUMBER>KF3P2</ITEMNUMBER>
<ITEMQTY>1</ITEMQTY>
<PRICE>8.27</PRICE>
</ITEM>
<ITEM>
<ITEMNUMBER>60RD2</ITEMNUMBER>
<ITEMQTY>1</ITEMQTY>
<PRICE>8.27</PRICE>
</ITEM>
</ITEMS>
</TIE>
</TIES>
</ORDER>
<ORDER>
<CUSNAME>743828552</CUSNAME>
<ORDERNUM>979794834</ORDERNUM>
<CITY />
<TIES>
<TIE>
<TIENUMBER>1</TIENUMBER>
<TIEQTY>1</TIEQTY>
<ITEMS>
<ITEM>
<ITEMNUMBER>K850M</ITEMNUMBER>
<ITEMQTY>1</ITEMQTY>
<PRICE>1.54</PRICE>
</ITEM>
<ITEM>
<ITEMNUMBER>T732H</ITEMNUMBER>
<ITEMQTY>1</ITEMQTY>
<PRICE>1.54</PRICE>
</ITEM>
</ITEMS>
</TIE>
</TIES>
</ORDER>
</ORDERS>
</CUSTOMSEDI>
XML2
<?xml version="1.0" encoding="utf-8"?>
<CUSTOMSEDI xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.dell.com/dbi/fsl/compliance/v1_0">
<ASNNUM>SXMSEO180814001D</ASNNUM>
<ORDERS>
<ORDER>
<CUSID>744400014</CUSID>
<ORDERNUM>979794834</ORDERNUM>
<TIES>
<TIE>
<TIENUMBER>1</TIENUMBER>
<TIEQTY>1</TIEQTY>
<ITEMS>
<ITEM>
<ITEMNUMBER>T732H</ITEMNUMBER>
<ITEMQTY>1</ITEMQTY>
<PRICE>1.54</PRICE>
</ITEM>
<ITEM>
<ITEMNUMBER>K850M</ITEMNUMBER>
<ITEMQTY>1</ITEMQTY>
<PRICE>1.54</PRICE>
</ITEM>
</ITEMS>
</TIE>
</TIES>
</ORDER>
<ORDER>
<CUSID>743138972</CUSID>
<CUSADDRESS>KLS Tokyo Terminal3-2-31 Yashio, Shinagawa, TokyoJapan</CUSADDRESS>
<ORDERNUM>979793524</ORDERNUM>
<TIES>
<TIE>
<TIENUMBER>1</TIENUMBER>
<TIEQTY>1</TIEQTY>
<ITEMS>
<ITEM>
<ITEMNUMBER>60RD2</ITEMNUMBER>
<ITEMQTY>1</ITEMQTY>
<PRICE>8.27</PRICE>
</ITEM>
<ITEM>
<ITEMNUMBER>KF3P2</ITEMNUMBER>
<ITEMQTY>25</ITEMQTY>
<PRICE>8.27</PRICE>
</ITEM>
</ITEMS>
</TIE>
</TIES>
</ORDER>
</ORDERS>
</CUSTOMSEDI>
Here is the difference.
If this tool could not solve your question, please let me know. I will test another tool.
Best Regards,
Wendy
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].
Thursday, September 13, 2018 7:52 AM
Firstly so thankful to you for your kind support and iam facing issues with this DiffPatchTool when comparing large xml files which are having more than 1000 lines of xml and the report showing is not accurate as it is highlighting the wrong sections hence i would like to try another tool or could you please help me in implementing XSLT for comparing and showing only the differences.
Kindly awaiting your Response
Thanks
ram
Thursday, September 20, 2018 6:56 AM
Hi coolram4u,
As I know, the XSLT is a language for transforming XML documents into other XML documents. Why do you want to use this to compare xml file?
Best Regards,
Wendy
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].
Thursday, September 20, 2018 7:59 AM
>when comparing large xml files
If you remember - question about file size was a first question which I as you about in another topic.
Yes, there is a problem with huge files in comparison using XmlDiff.
If files are too big for XmlDiff I would recommend to import files in database - you can use two different schemas - and look on SQL to get a result - this would be much faster and far mach quicker to do.
LINQ - also will be useful, but it require a huge amount of memory.
Sincerely, Highly skilled coding monkey.