One Star

Comparing 2 XML files

hi everyone,
i'm trying to compare two XML files that have the same structure. My question is: How can i do to show the difference between the two XML files. Any solutions?
Best regards.
Pegaz
42 REPLIES
One Star

Re: Comparing 2 XML files

Are your data sorted?
One Star

Re: Comparing 2 XML files

Are your differents data in the same file or they might be in both file?
One Star

Re: Comparing 2 XML files

my data are sorted, and i have 2 XML files having the same structure.
One Star

Re: Comparing 2 XML files

I didn't find yet the solution to know the differences between the two file but I've found a solution to know the similar data.
Are you interested?
One Star

Re: Comparing 2 XML files

For sure! thank's
One Star

Re: Comparing 2 XML files

I did this example with two CSV file, with the same structure but with some differents values.
I've used a tUnite and after a tUniqRow.
I've used all the field as Key attribute in the tUniqRow.
As output use the Duplicates flow to see all the similar values.
However if file1 and file2 have a same row= you will see this row two times.
So I added a tAggregateRow and the groupby function in it for each field
One Star

Re: Comparing 2 XML files

i'm trying ur example...
One Star

Re: Comparing 2 XML files

i tried to realise a job concerning the comparaison of the 2 XML files.
Here is a screenshot of my job:

and here is the variables regarding the tFileCompare_1 settings:

Can you help me to resolve my problem, this is the error message:

Regards,
Pegaz
Employee

Re: Comparing 2 XML files

Hi,
Why do you have specific characters in "If no differences detected, display" field.
Your error is a CodeGenerator mistake due to a bad character in your component properties.
Regards,
One Star

Re: Comparing 2 XML files

Doesn't change anything when i delete specific characters Smiley Sad
Employee

Re: Comparing 2 XML files

Hi,
If you switch your designer tab to code tab, you will see the line in the codeGenerator with the compilation error.
Can you send a screenshot or a copy/paste of this area, please.
Regards;
One Star

Re: Comparing 2 XML files

you can try with two tfile list.
In each tFilelist you specified the directory and the name file
After you can use ((String)globalMap.get("tFileList_1_CURRENT_FILEPATH")) & ((String)globalMap.get("tFileList_2_CURRENT_FILEPATH"))
Employee

Re: Comparing 2 XML files

Hi,
In your case, you need Iterate only on one Folder to compare with one reference file.
Can you try this, remove tFileList2 component ?
You can find further information in our User Guide.
Regards;
One Star

Re: Comparing 2 XML files

my tfilecompare_1 output contains the default parameters(file, file_ref,moment,...) . I can't change it !
is it possible to change the output?
One Star

Re: Comparing 2 XML files

what do you want in your output?
One Star

Re: Comparing 2 XML files

i want to show as an output my own columns related to my project
One Star

Re: Comparing 2 XML files

your own columns? What do you mean? You want to choose only some few columns from the tFileCompare or the row of each file?
One Star

Re: Comparing 2 XML files

yes, only some few columns from the tFileCompare
One Star

Re: Comparing 2 XML files

you can use a tMap Smiley Happy
One Star

Re: Comparing 2 XML files

hello,
I need to compare 2 XML files. Actually, I can do this, show if the files differ or not and how many lines do they differ.
My question is: How can i identify which row do they differ and what is the id. Let's consider this example:
xml1: xml2:
id= 12 id= 12
first_name= MACKLEY first_name= MACKLEY
last_name= bob last_name= david

I want to see as a result: the 2 XML files differ/ they differ on: last_name / the id= 12
Regards.
Pegaz
One Star

Re: Comparing 2 XML files

I'm thinking that it would be a really good idea to developp a new component that permits to compare two files row by row.
Please wait for a talend team opinion but I think it will be an option to put it into the buggtracker
One Star

Re: Comparing 2 XML files

i'm trying to switch to an other solution using tmap.
tFileInputXML_1--------->
tMap_1----------> tLogRow_1
tFileInputXML_2--------->
any suggestions?
thank's
One Star

Re: Comparing 2 XML files

do you have many fields to compare?
One Star

Re: Comparing 2 XML files

no, only 2 fields at this moment.
One Star

Re: Comparing 2 XML files

Do u know how to compare two fields using tmap? and return a message saying for instence: the files differ If both of fields aren't the same and , the files are the same if they are.??
One Star

Re: Comparing 2 XML files

ok so it exists a solution with a tMap but it's quite heavy...
You can use the tmap if you are sure that your id won't change at any moment.
You use a filter :
for the first flow :
!row1.first_name.equals( row2.first_name)
for the second :
!row1.last_name.equals(row2.last_name )
After you can set your output fields to :
first:
"issue in id "+row1.id+" : "+row1.first_name+" different to "+row2.first_name
second:
"issue in line "+row1.id+" : "+row1.last_name+" different to "+row2.last_name
One Star

Re: Comparing 2 XML files

could you put a screenshot of ur job plz?
One Star

Re: Comparing 2 XML files

of course, I use 2 csv files a two output
One Star

Re: Comparing 2 XML files

i have this error message: cannot convert string to integer when i put: "issue in line "+row1.id+" : "+row1.first_name+" different to "+row2.first_name