[erlang-questions] Re: Compare XML string

Richard O'Keefe <>
Thu Jul 1 06:04:49 CEST 2010


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<>  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:
>>>
>> ________________________________________________________________
>> erlang-questions (at) erlang.org mailing list.
>> See http://www.erlang.org/faq.html
>> To unsubscribe; mailto:
>>
>>
>>
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
>
>



More information about the erlang-questions mailing list