Quantcast

Compare XML string

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Compare XML string

Sand T
Hi,

I need to compare two given XML string to ensure that the two strings
are identical or not at runtime. Does anyone have any idea on how to
do this in erlang?

Following are some of the examples
Given String
<response type=\"progress\" im=\"IM\" login=\"ABC\"
code=\"102\">Authentication Successful ...</response>
Exp String:
<response type=\"progress\" im=\"IM\" login=\"ABC\"
code=\"102\">Authentication Successful ...</response>

Eq 2:
Given String
<response type=\"progress\" im=\"IM\" login=\"ABC\"
code=\"102\">Authentication Successful ...</response>
<buddies im=\"IM\" login=\"ABC\"><buddy name=\"XYZ\" nickname=\"\"
status=\"offline\" custom=\"Is offline\" group=\"Friends\"
blocked=\"no\"/></buddies>

Expected:
<response type=\"progress\" im=\"IM\" login=\"ABC\" >Authentication
Successful ...</response>
<buddies im=\"IM\" login=\"ABC\" ><buddy name=\"XYZ\" nickname=\"\"
status=\"online\" custom=\"Is offline\" group=\"Friends\"
blocked=\"no\"/></buddies>

Regards,
Sandeep

________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Compare XML string

Sand T
Any suggestions from the team?

Regards,
Sandeep

> Hi Michael,
>
> I need to compare two XML string and the XML string attribute order,
> value can be different as you pointed out in your explanation. The
> comparison should give *false* only if the value of attribute is
> different or some attribute is missing, It should not give *false* if
> order of attribute is different. However, when I perform,
>
>>   {Given, _} = xmerl_scan:file("Given.xml"),
>>   {Expected,_} = xmerl_scan:file("Expected.xml"),
>> --then directly compare the resulting data structures in the obvious (?)
>> way:
>>   Virtually_identical = (Given =:= Expected)
>
> it gives me *false* if the order of attribute is different. The two
> example string that I used is
>
> S="<xml session=\"123\"><response type=\"progress\" code=\"100\"
> im=\"IM\" login=\"L\">Connected To Server</response></xml>".
>
> Exp = "<xml session=\"123\"><response type=\"progress\" im=\"IM\"
> code=\"100\" login=\"L\">Connected To Server</response></xml>".
>
> Regards,
> Sandeep
>
> On Fri, Jun 25, 2010 at 8:56 PM, Michael Turner
> <[hidden email]> wrote:
>> I feel like I must be missing something in your question.  Let's say that
>> the Given XML is in a file Given.xml, the Expected in a file Expected.xml.
>>  Just read them in--
>>   {Given, _} = xmerl_scan:file("Given.xml"),
>>   {Expected,_} = xmerl_scan:file("Expected.xml"),
>> --then directly compare the resulting data structures in the obvious (?)
>> way:
>>   Virtually_identical = (Given =:= Expected)
>> Of course, the two files could be different in certain inconsequential
>> details, such as having have the same set of attributes in an XML element
>> but in a different order, and/or having different tag formatting in
>> whitespace.  E.g., Expected.xml might literally have
>>   <sometag id="me" value="1 cent"/>
>> while Given.xml had
>>   <sometag
>>         value = "1 cent"
>>         id = me
>>   />
>> but the comparison above with Given with Expected (the resulting tree
>> structures) would still yield true all other things being equal.  Isn't that
>> what you want, though?
>> If you want to know the contents of the two files *AS STRINGS* are identical
>> (regardless of whether they are XML, I suppose), why not just read them in
>> (say as binaries) and compare them?
>> -michael turner
>>
>> On Fri, Jun 25, 2010 at 3:43 PM, Sand T <[hidden email]> wrote:
>>>
>>> Hi,
>>>
>>> I need to compare two given XML string to ensure that the two strings
>>> are identical or not at runtime. Does anyone have any idea on how to
>>> do this in erlang?
>>>
>>> Following are some of the examples
>>> Given String
>>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
>>> code=\"102\">Authentication Successful ...</response>
>>> Exp String:
>>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
>>> code=\"102\">Authentication Successful ...</response>
>>>
>>> Eq 2:
>>> Given String
>>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
>>> code=\"102\">Authentication Successful ...</response>
>>> <buddies im=\"IM\" login=\"ABC\"><buddy name=\"XYZ\" nickname=\"\"
>>> status=\"offline\" custom=\"Is offline\" group=\"Friends\"
>>> blocked=\"no\"/></buddies>
>>>
>>> Expected:
>>> <response type=\"progress\" im=\"IM\" login=\"ABC\" >Authentication
>>> Successful ...</response>
>>> <buddies im=\"IM\" login=\"ABC\" ><buddy name=\"XYZ\" nickname=\"\"
>>> status=\"online\" custom=\"Is offline\" group=\"Friends\"
>>> blocked=\"no\"/></buddies>
>>>
>>> Regards,
>>> Sandeep
>>>
>>> ________________________________________________________________
>>> erlang-questions (at) erlang.org mailing list.
>>> See http://www.erlang.org/faq.html
>>> To unsubscribe; mailto:[hidden email]
>>>
>>
>>
>

________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Compare XML string

Willem de Jong-2
Hi Sandeep,

If you have an XSD for the XML, then you can use erlsom:scan(). I believe
that the output for two different XMLs with the same "meaning" will be
identical. It will also help you to identify XML strings that are not
correct (ie not in accordance with the XSD), and it may make the processing
of the XML easier.

You can find erlsom on sourceforge or on github (
http://github.com/willemdj/erlsom)

Regards,
Willem




On Tue, Jun 29, 2010 at 6:53 AM, Sand T <[hidden email]> wrote:

> Any suggestions from the team?
>
> Regards,
> Sandeep
>
> > Hi Michael,
> >
> > I need to compare two XML string and the XML string attribute order,
> > value can be different as you pointed out in your explanation. The
> > comparison should give *false* only if the value of attribute is
> > different or some attribute is missing, It should not give *false* if
> > order of attribute is different. However, when I perform,
> >
> >>   {Given, _} = xmerl_scan:file("Given.xml"),
> >>   {Expected,_} = xmerl_scan:file("Expected.xml"),
> >> --then directly compare the resulting data structures in the obvious (?)
> >> way:
> >>   Virtually_identical = (Given =:= Expected)
> >
> > it gives me *false* if the order of attribute is different. The two
> > example string that I used is
> >
> > S="<xml session=\"123\"><response type=\"progress\" code=\"100\"
> > im=\"IM\" login=\"L\">Connected To Server</response></xml>".
> >
> > Exp = "<xml session=\"123\"><response type=\"progress\" im=\"IM\"
> > code=\"100\" login=\"L\">Connected To Server</response></xml>".
> >
> > Regards,
> > Sandeep
> >
> > On Fri, Jun 25, 2010 at 8:56 PM, Michael Turner
> > <[hidden email]> wrote:
> >> I feel like I must be missing something in your question.  Let's say
> that
> >> the Given XML is in a file Given.xml, the Expected in a file
> Expected.xml.
> >>  Just read them in--
> >>   {Given, _} = xmerl_scan:file("Given.xml"),
> >>   {Expected,_} = xmerl_scan:file("Expected.xml"),
> >> --then directly compare the resulting data structures in the obvious (?)
> >> way:
> >>   Virtually_identical = (Given =:= Expected)
> >> Of course, the two files could be different in certain inconsequential
> >> details, such as having have the same set of attributes in an XML
> element
> >> but in a different order, and/or having different tag formatting in
> >> whitespace.  E.g., Expected.xml might literally have
> >>   <sometag id="me" value="1 cent"/>
> >> while Given.xml had
> >>   <sometag
> >>         value = "1 cent"
> >>         id = me
> >>   />
> >> but the comparison above with Given with Expected (the resulting tree
> >> structures) would still yield true all other things being equal.  Isn't
> that
> >> what you want, though?
> >> If you want to know the contents of the two files *AS STRINGS* are
> identical
> >> (regardless of whether they are XML, I suppose), why not just read them
> in
> >> (say as binaries) and compare them?
> >> -michael turner
>  >>
> >> On Fri, Jun 25, 2010 at 3:43 PM, Sand T <[hidden email]>
> wrote:
> >>>
> >>> Hi,
> >>>
> >>> I need to compare two given XML string to ensure that the two strings
> >>> are identical or not at runtime. Does anyone have any idea on how to
> >>> do this in erlang?
> >>>
> >>> Following are some of the examples
> >>> Given String
> >>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
> >>> code=\"102\">Authentication Successful ...</response>
> >>> Exp String:
> >>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
> >>> code=\"102\">Authentication Successful ...</response>
> >>>
> >>> Eq 2:
> >>> Given String
> >>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
> >>> code=\"102\">Authentication Successful ...</response>
> >>> <buddies im=\"IM\" login=\"ABC\"><buddy name=\"XYZ\" nickname=\"\"
> >>> status=\"offline\" custom=\"Is offline\" group=\"Friends\"
> >>> blocked=\"no\"/></buddies>
> >>>
> >>> Expected:
> >>> <response type=\"progress\" im=\"IM\" login=\"ABC\" >Authentication
> >>> Successful ...</response>
> >>> <buddies im=\"IM\" login=\"ABC\" ><buddy name=\"XYZ\" nickname=\"\"
> >>> status=\"online\" custom=\"Is offline\" group=\"Friends\"
> >>> blocked=\"no\"/></buddies>
> >>>
> >>> Regards,
> >>> Sandeep
> >>>
> >>> ________________________________________________________________
> >>> erlang-questions (at) erlang.org mailing list.
> >>> See http://www.erlang.org/faq.html
> >>> To unsubscribe; mailto:[hidden email]
> >>>
> >>
> >>
> >
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:[hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Compare XML string

Sand T
Hi Willem,

Thanks for the response. I am using erlsom but dont have XSD as I am
getting all this XML as a part of server responses during runtime. All
I need to do is compare the server response with the expected response
and conclude whether the server response is exactly similar to the
expected [XML] response.

Expecting some quick response.

Regards,
Sandeep

On Tue, Jun 29, 2010 at 12:23 PM, Willem de Jong <[hidden email]> wrote:

> Hi Sandeep,
>
> If you have an XSD for the XML, then you can use erlsom:scan(). I believe
> that the output for two different XMLs with the same "meaning" will be
> identical. It will also help you to identify XML strings that are not
> correct (ie not in accordance with the XSD), and it may make the processing
> of the XML easier.
>
> You can find erlsom on sourceforge or on github
> (http://github.com/willemdj/erlsom)
>
> Regards,
> Willem
>
>
>
> On Tue, Jun 29, 2010 at 6:53 AM, Sand T <[hidden email]> wrote:
>>
>> Any suggestions from the team?
>>
>> Regards,
>> Sandeep
>>
>> > Hi Michael,
>> >
>> > I need to compare two XML string and the XML string attribute order,
>> > value can be different as you pointed out in your explanation. The
>> > comparison should give *false* only if the value of attribute is
>> > different or some attribute is missing, It should not give *false* if
>> > order of attribute is different. However, when I perform,
>> >
>> >>   {Given, _} = xmerl_scan:file("Given.xml"),
>> >>   {Expected,_} = xmerl_scan:file("Expected.xml"),
>> >> --then directly compare the resulting data structures in the obvious
>> >> (?)
>> >> way:
>> >>   Virtually_identical = (Given =:= Expected)
>> >
>> > it gives me *false* if the order of attribute is different. The two
>> > example string that I used is
>> >
>> > S="<xml session=\"123\"><response type=\"progress\" code=\"100\"
>> > im=\"IM\" login=\"L\">Connected To Server</response></xml>".
>> >
>> > Exp = "<xml session=\"123\"><response type=\"progress\" im=\"IM\"
>> > code=\"100\" login=\"L\">Connected To Server</response></xml>".
>> >
>> > Regards,
>> > Sandeep
>> >
>> > On Fri, Jun 25, 2010 at 8:56 PM, Michael Turner
>> > <[hidden email]> wrote:
>> >> I feel like I must be missing something in your question.  Let's say
>> >> that
>> >> the Given XML is in a file Given.xml, the Expected in a file
>> >> Expected.xml.
>> >>  Just read them in--
>> >>   {Given, _} = xmerl_scan:file("Given.xml"),
>> >>   {Expected,_} = xmerl_scan:file("Expected.xml"),
>> >> --then directly compare the resulting data structures in the obvious
>> >> (?)
>> >> way:
>> >>   Virtually_identical = (Given =:= Expected)
>> >> Of course, the two files could be different in certain inconsequential
>> >> details, such as having have the same set of attributes in an XML
>> >> element
>> >> but in a different order, and/or having different tag formatting in
>> >> whitespace.  E.g., Expected.xml might literally have
>> >>   <sometag id="me" value="1 cent"/>
>> >> while Given.xml had
>> >>   <sometag
>> >>         value = "1 cent"
>> >>         id = me
>> >>   />
>> >> but the comparison above with Given with Expected (the resulting tree
>> >> structures) would still yield true all other things being equal.  Isn't
>> >> that
>> >> what you want, though?
>> >> If you want to know the contents of the two files *AS STRINGS* are
>> >> identical
>> >> (regardless of whether they are XML, I suppose), why not just read them
>> >> in
>> >> (say as binaries) and compare them?
>> >> -michael turner
>> >>
>> >> On Fri, Jun 25, 2010 at 3:43 PM, Sand T <[hidden email]>
>> >> wrote:
>> >>>
>> >>> Hi,
>> >>>
>> >>> I need to compare two given XML string to ensure that the two strings
>> >>> are identical or not at runtime. Does anyone have any idea on how to
>> >>> do this in erlang?
>> >>>
>> >>> Following are some of the examples
>> >>> Given String
>> >>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
>> >>> code=\"102\">Authentication Successful ...</response>
>> >>> Exp String:
>> >>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
>> >>> code=\"102\">Authentication Successful ...</response>
>> >>>
>> >>> Eq 2:
>> >>> Given String
>> >>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
>> >>> code=\"102\">Authentication Successful ...</response>
>> >>> <buddies im=\"IM\" login=\"ABC\"><buddy name=\"XYZ\" nickname=\"\"
>> >>> status=\"offline\" custom=\"Is offline\" group=\"Friends\"
>> >>> blocked=\"no\"/></buddies>
>> >>>
>> >>> Expected:
>> >>> <response type=\"progress\" im=\"IM\" login=\"ABC\" >Authentication
>> >>> Successful ...</response>
>> >>> <buddies im=\"IM\" login=\"ABC\" ><buddy name=\"XYZ\" nickname=\"\"
>> >>> status=\"online\" custom=\"Is offline\" group=\"Friends\"
>> >>> blocked=\"no\"/></buddies>
>> >>>
>> >>> Regards,
>> >>> Sandeep
>> >>>
>> >>> ________________________________________________________________
>> >>> erlang-questions (at) erlang.org mailing list.
>> >>> See http://www.erlang.org/faq.html
>> >>> To unsubscribe; mailto:[hidden email]
>> >>>
>> >>
>> >>
>> >
>>
>> ________________________________________________________________
>> erlang-questions (at) erlang.org mailing list.
>> See http://www.erlang.org/faq.html
>> To unsubscribe; mailto:[hidden email]
>>
>
>

________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Compare XML string

Mazen Harake-3
  "Exactly similar" :)

Anyway; perhaps if you flatten the whole string and sort it. It should
be the same. Maybe that is a good enough solution

/Mazen

On 29/06/2010 10:03, Sand T wrote:
> exactly similar
---------------------------------------------------

---------------------------------------------------

WE'VE CHANGED NAMES!

Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLANG SOLUTIONS LTD.

www.erlang-solutions.com


________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Compare XML string

Willem de Jong-2
In reply to this post by Sand T
Hi,

If you take a look at the erlsom source file erlsom_simpleform.erl, you
could try replacing the line 156:

  lists:reverse(Acc);

by:

  lists:sort(Acc);

That way you can compare the results of erlsom:simple_form(Given) and
erlsom:simple_form(Expected) (Note: I didn't test this..)
Regards,
Willem


On Tue, Jun 29, 2010 at 9:03 AM, Sand T <[hidden email]> wrote:

> Hi Willem,
>
> Thanks for the response. I am using erlsom but dont have XSD as I am
> getting all this XML as a part of server responses during runtime. All
> I need to do is compare the server response with the expected response
> and conclude whether the server response is exactly similar to the
> expected [XML] response.
>
> Expecting some quick response.
>
> Regards,
> Sandeep
>
> On Tue, Jun 29, 2010 at 12:23 PM, Willem de Jong <[hidden email]>
> wrote:
>  > Hi Sandeep,
> >
> > If you have an XSD for the XML, then you can use erlsom:scan(). I believe
> > that the output for two different XMLs with the same "meaning" will be
> > identical. It will also help you to identify XML strings that are not
> > correct (ie not in accordance with the XSD), and it may make the
> processing
> > of the XML easier.
> >
> > You can find erlsom on sourceforge or on github
> > (http://github.com/willemdj/erlsom)
> >
> > Regards,
> > Willem
> >
> >
> >
> > On Tue, Jun 29, 2010 at 6:53 AM, Sand T <[hidden email]> wrote:
> >>
> >> Any suggestions from the team?
> >>
> >> Regards,
> >> Sandeep
> >>
> >> > Hi Michael,
> >> >
> >> > I need to compare two XML string and the XML string attribute order,
> >> > value can be different as you pointed out in your explanation. The
> >> > comparison should give *false* only if the value of attribute is
> >> > different or some attribute is missing, It should not give *false* if
> >> > order of attribute is different. However, when I perform,
> >> >
> >> >>   {Given, _} = xmerl_scan:file("Given.xml"),
> >> >>   {Expected,_} = xmerl_scan:file("Expected.xml"),
> >> >> --then directly compare the resulting data structures in the obvious
> >> >> (?)
> >> >> way:
> >> >>   Virtually_identical = (Given =:= Expected)
> >> >
> >> > it gives me *false* if the order of attribute is different. The two
> >> > example string that I used is
> >> >
> >> > S="<xml session=\"123\"><response type=\"progress\" code=\"100\"
> >> > im=\"IM\" login=\"L\">Connected To Server</response></xml>".
> >> >
> >> > Exp = "<xml session=\"123\"><response type=\"progress\" im=\"IM\"
> >> > code=\"100\" login=\"L\">Connected To Server</response></xml>".
> >> >
> >> > Regards,
> >> > Sandeep
> >> >
> >> > On Fri, Jun 25, 2010 at 8:56 PM, Michael Turner
> >> > <[hidden email]> wrote:
> >> >> I feel like I must be missing something in your question.  Let's say
> >> >> that
> >> >> the Given XML is in a file Given.xml, the Expected in a file
> >> >> Expected.xml.
> >> >>  Just read them in--
> >> >>   {Given, _} = xmerl_scan:file("Given.xml"),
> >> >>   {Expected,_} = xmerl_scan:file("Expected.xml"),
> >> >> --then directly compare the resulting data structures in the obvious
> >> >> (?)
> >> >> way:
> >> >>   Virtually_identical = (Given =:= Expected)
> >> >> Of course, the two files could be different in certain
> inconsequential
> >> >> details, such as having have the same set of attributes in an XML
> >> >> element
> >> >> but in a different order, and/or having different tag formatting in
> >> >> whitespace.  E.g., Expected.xml might literally have
> >> >>   <sometag id="me" value="1 cent"/>
> >> >> while Given.xml had
> >> >>   <sometag
> >> >>         value = "1 cent"
> >> >>         id = me
> >> >>   />
> >> >> but the comparison above with Given with Expected (the resulting tree
> >> >> structures) would still yield true all other things being equal.
>  Isn't
> >> >> that
> >> >> what you want, though?
> >> >> If you want to know the contents of the two files *AS STRINGS* are
> >> >> identical
> >> >> (regardless of whether they are XML, I suppose), why not just read
> them
> >> >> in
> >> >> (say as binaries) and compare them?
> >> >> -michael turner
> >> >>
> >> >> On Fri, Jun 25, 2010 at 3:43 PM, Sand T <[hidden email]>
> >> >> wrote:
> >> >>>
> >> >>> Hi,
> >> >>>
> >> >>> I need to compare two given XML string to ensure that the two
> strings
> >> >>> are identical or not at runtime. Does anyone have any idea on how to
> >> >>> do this in erlang?
> >> >>>
> >> >>> Following are some of the examples
> >> >>> Given String
> >> >>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
> >> >>> code=\"102\">Authentication Successful ...</response>
> >> >>> Exp String:
> >> >>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
> >> >>> code=\"102\">Authentication Successful ...</response>
> >> >>>
> >> >>> Eq 2:
> >> >>> Given String
> >> >>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
> >> >>> code=\"102\">Authentication Successful ...</response>
> >> >>> <buddies im=\"IM\" login=\"ABC\"><buddy name=\"XYZ\" nickname=\"\"
> >> >>> status=\"offline\" custom=\"Is offline\" group=\"Friends\"
> >> >>> blocked=\"no\"/></buddies>
> >> >>>
> >> >>> Expected:
> >> >>> <response type=\"progress\" im=\"IM\" login=\"ABC\" >Authentication
> >> >>> Successful ...</response>
> >> >>> <buddies im=\"IM\" login=\"ABC\" ><buddy name=\"XYZ\" nickname=\"\"
> >> >>> status=\"online\" custom=\"Is offline\" group=\"Friends\"
> >> >>> blocked=\"no\"/></buddies>
> >> >>>
> >> >>> Regards,
> >> >>> Sandeep
> >> >>>
> >> >>> ________________________________________________________________
> >> >>> erlang-questions (at) erlang.org mailing list.
> >> >>> See http://www.erlang.org/faq.html
> >> >>> To unsubscribe; mailto:[hidden email]
> >> >>>
> >> >>
> >> >>
> >> >
> >>
> >> ________________________________________________________________
> >> erlang-questions (at) erlang.org mailing list.
> >> See http://www.erlang.org/faq.html
> >> To unsubscribe; mailto:[hidden email]
> >>
> >
> >
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:[hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Compare XML string

Steve Davis
In reply to this post by Sand T
Am I under-thinking this if I say:

case GivenString of
ExpectedString -> ok;
_ -> error
end.

...or is the question really as simple as it sounds.

/s

On Jun 25, 1:43 am, Sand T <[hidden email]> wrote:

> Hi,
>
> I need to compare two given XML string to ensure that the two strings
> are identical or not at runtime. Does anyone have any idea on how to
> do this in erlang?
>
> Following are some of the examples
> Given String
> <response type=\"progress\" im=\"IM\" login=\"ABC\"
> code=\"102\">Authentication Successful ...</response>
> Exp String:
> <response type=\"progress\" im=\"IM\" login=\"ABC\"
> code=\"102\">Authentication Successful ...</response>
>
> Eq 2:
> Given String
> <response type=\"progress\" im=\"IM\" login=\"ABC\"
> code=\"102\">Authentication Successful ...</response>
> <buddies im=\"IM\" login=\"ABC\"><buddy name=\"XYZ\" nickname=\"\"
> status=\"offline\" custom=\"Is offline\" group=\"Friends\"
> blocked=\"no\"/></buddies>
>
> Expected:
> <response type=\"progress\" im=\"IM\" login=\"ABC\" >Authentication
> Successful ...</response>
> <buddies im=\"IM\" login=\"ABC\" ><buddy name=\"XYZ\" nickname=\"\"
> status=\"online\" custom=\"Is offline\" group=\"Friends\"
> blocked=\"no\"/></buddies>
>
> Regards,
> Sandeep
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> Seehttp://www.erlang.org/faq.html
> To unsubscribe; mailto:[hidden email]

________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Compare XML string

Dmitry Belyaev
First of all, what does author want to compare: plain strings or xml
documents?

If documents (or parts of documents) then what about order of attributes
and child elements? Does it matter?

<item attr1="value1" attr2="value2"/>
<item attr2="value2" attr1="value1></item>

Sand, do you count them identical?

Dmitry Belyaev


On 06/29/2010 03:32 PM, Steve Davis wrote:

> Am I under-thinking this if I say:
>
> case GivenString of
> ExpectedString ->  ok;
> _ ->  error
> end.
>
> ..or is the question really as simple as it sounds.
>
> /s
>
> On Jun 25, 1:43 am, Sand T<[hidden email]>  wrote:
>    
>> Hi,
>>
>> I need to compare two given XML string to ensure that the two strings
>> are identical or not at runtime. Does anyone have any idea on how to
>> do this in erlang?
>>
>> Following are some of the examples
>> Given String
>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
>> code=\"102\">Authentication Successful ...</response>
>> Exp String:
>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
>> code=\"102\">Authentication Successful ...</response>
>>
>> Eq 2:
>> Given String
>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
>> code=\"102\">Authentication Successful ...</response>
>> <buddies im=\"IM\" login=\"ABC\"><buddy name=\"XYZ\" nickname=\"\"
>> status=\"offline\" custom=\"Is offline\" group=\"Friends\"
>> blocked=\"no\"/></buddies>
>>
>> Expected:
>> <response type=\"progress\" im=\"IM\" login=\"ABC\">Authentication
>> Successful ...</response>
>> <buddies im=\"IM\" login=\"ABC\"><buddy name=\"XYZ\" nickname=\"\"
>> status=\"online\" custom=\"Is offline\" group=\"Friends\"
>> blocked=\"no\"/></buddies>
>>
>> Regards,
>> Sandeep
>>
>> ________________________________________________________________
>> erlang-questions (at) erlang.org mailing list.
>> Seehttp://www.erlang.org/faq.html
>> To unsubscribe; mailto:[hidden email]
>>      
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:[hidden email]
>
>
>    

________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Compare XML string

Sand T
Yes, both are identical. I need to compare xml strings/documents

~Sand

On Tue, Jun 29, 2010 at 5:10 PM, Dmitry Belyaev <[hidden email]> wrote:

> First of all, what does author want to compare: plain strings or xml
> documents?
>
> If documents (or parts of documents) then what about order of attributes and
> child elements? Does it matter?
>
> <item attr1="value1" attr2="value2"/>
> <item attr2="value2" attr1="value1></item>
>
> Sand, do you count them identical?
>
> Dmitry Belyaev
>
>
> On 06/29/2010 03:32 PM, Steve Davis wrote:
>>
>> Am I under-thinking this if I say:
>>
>> case GivenString of
>> ExpectedString ->  ok;
>> _ ->  error
>> end.
>>
>> ..or is the question really as simple as it sounds.
>>
>> /s
>>
>> On Jun 25, 1:43 am, Sand T<[hidden email]>  wrote:
>>
>>>
>>> Hi,
>>>
>>> I need to compare two given XML string to ensure that the two strings
>>> are identical or not at runtime. Does anyone have any idea on how to
>>> do this in erlang?
>>>
>>> Following are some of the examples
>>> Given String
>>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
>>> code=\"102\">Authentication Successful ...</response>
>>> Exp String:
>>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
>>> code=\"102\">Authentication Successful ...</response>
>>>
>>> Eq 2:
>>> Given String
>>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
>>> code=\"102\">Authentication Successful ...</response>
>>> <buddies im=\"IM\" login=\"ABC\"><buddy name=\"XYZ\" nickname=\"\"
>>> status=\"offline\" custom=\"Is offline\" group=\"Friends\"
>>> blocked=\"no\"/></buddies>
>>>
>>> Expected:
>>> <response type=\"progress\" im=\"IM\" login=\"ABC\">Authentication
>>> Successful ...</response>
>>> <buddies im=\"IM\" login=\"ABC\"><buddy name=\"XYZ\" nickname=\"\"
>>> status=\"online\" custom=\"Is offline\" group=\"Friends\"
>>> blocked=\"no\"/></buddies>
>>>
>>> Regards,
>>> Sandeep
>>>
>>> ________________________________________________________________
>>> erlang-questions (at) erlang.org mailing list.
>>> Seehttp://www.erlang.org/faq.html
>>> To unsubscribe; mailto:[hidden email]
>>>
>>
>> ________________________________________________________________
>> erlang-questions (at) erlang.org mailing list.
>> See http://www.erlang.org/faq.html
>> To unsubscribe; mailto:[hidden email]
>>
>>
>>
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:[hidden email]
>
>

________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Compare XML string

Michael McDaniel-4
On Wed, Jun 30, 2010 at 09:17:36AM +0530, Sand T wrote:

> Yes, both are identical. I need to compare xml strings/documents
>
> ~Sand
>
> On Tue, Jun 29, 2010 at 5:10 PM, Dmitry Belyaev <[hidden email]> wrote:
> > First of all, what does author want to compare: plain strings or xml
> > documents?
> >
> > If documents (or parts of documents) then what about order of attributes and
> > child elements? Does it matter?
> >
> > <item attr1="value1" attr2="value2"/>
> > <item attr2="value2" attr1="value1></item>
> >
> > Sand, do you count them identical?
> >
> > Dmitry Belyaev
> >
> >
> > On 06/29/2010 03:32 PM, Steve Davis wrote:
> >>
> >> Am I under-thinking this if I say:
> >>
> >> case GivenString of
> >> ExpectedString ->  ok;
> >> _ ->  error
> >> end.
> >>
> >> ..or is the question really as simple as it sounds.
> >>
> >> /s
> >>
> >> On Jun 25, 1:43 am, Sand T<[hidden email]>  wrote:
> >>
> >>>
> >>> Hi,
> >>>
> >>> I need to compare two given XML string to ensure that the two strings
> >>> are identical or not at runtime. Does anyone have any idea on how to
> >>> do this in erlang?
> >>>
> >>> Following are some of the examples
> >>> Given String
> >>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
> >>> code=\"102\">Authentication Successful ...</response>
> >>> Exp String:
> >>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
> >>> code=\"102\">Authentication Successful ...</response>
> >>>
> >>> Eq 2:
> >>> Given String
> >>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
> >>> code=\"102\">Authentication Successful ...</response>
> >>> <buddies im=\"IM\" login=\"ABC\"><buddy name=\"XYZ\" nickname=\"\"
> >>> status=\"offline\" custom=\"Is offline\" group=\"Friends\"
> >>> blocked=\"no\"/></buddies>
> >>>
> >>> Expected:
> >>> <response type=\"progress\" im=\"IM\" login=\"ABC\">Authentication
> >>> Successful ...</response>
> >>> <buddies im=\"IM\" login=\"ABC\"><buddy name=\"XYZ\" nickname=\"\"
> >>> status=\"online\" custom=\"Is offline\" group=\"Friends\"
> >>> blocked=\"no\"/></buddies>
> >>>
> >>> Regards,
> >>> Sandeep
> >>>
________________________________________________________________


  truly *identical* ?  
  as in "a" = "a" is identical and "a" = "a " is not identical ?


  if so,


   try XML_one = XML_two of
      XML_one       -> true
      catch _:_     -> false
   end


~Michael


________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Compare XML string

Sand T
Hi,

Thanks a lot for the team suggestion, I use erlsom with XSD and it
works well. The tree generated for following XML are identical

<item attr1="value1" attr2="value2"/>
and
<item attr2="value2" attr1="value1 />

and are different for

<item attr1="value1" attr2="value2"/>
and
<item attr2="value20" attr1="value10 />

This makes the comparison easy. Also, the XSD enables xml validation
and hence the XML string can be verified for any missing/additional
attributes in XML.

I knew XSD can be used for XML validation in Java, but had no idea if
erlang has support for XSD. Thanks to Willem Jong for pointing this
out. However, xmerl still dont have support for XSD and hence using
erlsom makes better sense.

Once again, thanks for the team effort.

Regards,
Sandeep




On Wed, Jun 30, 2010 at 9:25 AM, Michael McDaniel <[hidden email]> wrote:

> On Wed, Jun 30, 2010 at 09:17:36AM +0530, Sand T wrote:
>> Yes, both are identical. I need to compare xml strings/documents
>>
>> ~Sand
>>
>> On Tue, Jun 29, 2010 at 5:10 PM, Dmitry Belyaev <[hidden email]> wrote:
>> > First of all, what does author want to compare: plain strings or xml
>> > documents?
>> >
>> > If documents (or parts of documents) then what about order of attributes and
>> > child elements? Does it matter?
>> >
>> > <item attr1="value1" attr2="value2"/>
>> > <item attr2="value2" attr1="value1></item>
>> >
>> > Sand, do you count them identical?
>> >
>> > Dmitry Belyaev
>> >
>> >
>> > On 06/29/2010 03:32 PM, Steve Davis wrote:
>> >>
>> >> Am I under-thinking this if I say:
>> >>
>> >> case GivenString of
>> >> ExpectedString ->  ok;
>> >> _ ->  error
>> >> end.
>> >>
>> >> ..or is the question really as simple as it sounds.
>> >>
>> >> /s
>> >>
>> >> On Jun 25, 1:43 am, Sand T<[hidden email]>  wrote:
>> >>
>> >>>
>> >>> Hi,
>> >>>
>> >>> I need to compare two given XML string to ensure that the two strings
>> >>> are identical or not at runtime. Does anyone have any idea on how to
>> >>> do this in erlang?
>> >>>
>> >>> Following are some of the examples
>> >>> Given String
>> >>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
>> >>> code=\"102\">Authentication Successful ...</response>
>> >>> Exp String:
>> >>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
>> >>> code=\"102\">Authentication Successful ...</response>
>> >>>
>> >>> Eq 2:
>> >>> Given String
>> >>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
>> >>> code=\"102\">Authentication Successful ...</response>
>> >>> <buddies im=\"IM\" login=\"ABC\"><buddy name=\"XYZ\" nickname=\"\"
>> >>> status=\"offline\" custom=\"Is offline\" group=\"Friends\"
>> >>> blocked=\"no\"/></buddies>
>> >>>
>> >>> Expected:
>> >>> <response type=\"progress\" im=\"IM\" login=\"ABC\">Authentication
>> >>> Successful ...</response>
>> >>> <buddies im=\"IM\" login=\"ABC\"><buddy name=\"XYZ\" nickname=\"\"
>> >>> status=\"online\" custom=\"Is offline\" group=\"Friends\"
>> >>> blocked=\"no\"/></buddies>
>> >>>
>> >>> Regards,
>> >>> Sandeep
>> >>>
> ________________________________________________________________
>
>
>  truly *identical* ?
>  as in "a" = "a" is identical and "a" = "a " is not identical ?
>
>
>  if so,
>
>
>   try XML_one = XML_two of
>      XML_one       -> true
>      catch _:_     -> false
>   end
>
>
> ~Michael
>
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:[hidden email]
>
>

________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Compare XML string

Richard O'Keefe
In reply to this post by Dmitry Belyaev

On Jun 29, 2010, at 11:40 PM, Dmitry Belyaev wrote:

> First of all, what does author want to compare: plain strings or xml  
> documents?
>
> If documents (or parts of documents) then what about order of  
> attributes and child elements? Does it matter?

A structure-based XML application shouldn't care what the order
of attributes is.  (In particular, given that XML, like SGML
before it, allows defaulting of attributes, I don't believe there
is any definition anywhere of where the defaulted attributes would
go in any sequence.)  Here's what I'm getting at:

f% cat foo.xml
<!DOCTYPE foo [
  <!ELEMENT foo (bar,bar)>
  <!ELEMENT bar EMPTY>
  <!ATTLIST bar x CDATA "X" y CDATA "Y">
]>
<foo>
  <bar x="X"/>
  <bar y="Y"/>
</foo>

The two instances of <bar...> look different, but
after defaulting, they have the same values for all attributes:

f% xmls foo.xml | qe -hr
{document,[{root,"-"}],[
  {foo,[],[
   {bar,[{y,"Y"},{x,"X"}],[]},
   {bar,[{y,"Y"},{x,"X"}],[]}]}]}.

This tool-chain ends up putting attributes in reverse alphabetic
order.  (xmls puts them in alphabetic order after defaulting,
then qe, being rather lazy internally, reverses them.)
>
> <item attr1="value1" attr2="value2"/>
> <item attr2="value2" attr1="value1></item>
>
> Sand, do you count them identical?

Any sensible XML application other than an editor *must*.

>
> Dmitry Belyaev
>
>
> On 06/29/2010 03:32 PM, Steve Davis wrote:
>> Am I under-thinking this if I say:
>>
>> case GivenString of
>> ExpectedString ->  ok;
>> _ ->  error
>> end.
>>
>> ..or is the question really as simple as it sounds.
>>
>> /s
>>
>> On Jun 25, 1:43 am, Sand T<[hidden email]>  wrote:
>>
>>> Hi,
>>>
>>> I need to compare two given XML string to ensure that the two  
>>> strings
>>> are identical or not at runtime. Does anyone have any idea on how to
>>> do this in erlang?
>>>
>>> Following are some of the examples
>>> Given String
>>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
>>> code=\"102\">Authentication Successful ...</response>
>>> Exp String:
>>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
>>> code=\"102\">Authentication Successful ...</response>
>>>
>>> Eq 2:
>>> Given String
>>> <response type=\"progress\" im=\"IM\" login=\"ABC\"
>>> code=\"102\">Authentication Successful ...</response>
>>> <buddies im=\"IM\" login=\"ABC\"><buddy name=\"XYZ\" nickname=\"\"
>>> status=\"offline\" custom=\"Is offline\" group=\"Friends\"
>>> blocked=\"no\"/></buddies>
>>>
>>> Expected:
>>> <response type=\"progress\" im=\"IM\" login=\"ABC\">Authentication
>>> Successful ...</response>
>>> <buddies im=\"IM\" login=\"ABC\"><buddy name=\"XYZ\" nickname=\"\"
>>> status=\"online\" custom=\"Is offline\" group=\"Friends\"
>>> blocked=\"no\"/></buddies>
>>>
>>> Regards,
>>> Sandeep
>>>
>>> ________________________________________________________________
>>> erlang-questions (at) erlang.org mailing list.
>>> Seehttp://www.erlang.org/faq.html
>>> To unsubscribe; mailto:[hidden email]
>>>
>> ________________________________________________________________
>> erlang-questions (at) erlang.org mailing list.
>> See http://www.erlang.org/faq.html
>> To unsubscribe; mailto:[hidden email]
>>
>>
>>
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:[hidden email]
>
>


________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:[hidden email]

Loading...