How to parse attributes in ruby?

Dear friends,

I’am in process of creating a new parser class. My parser was showing
parsing errors in case of input like,

<product prod_name="jean" size=" 24" boot-cut" price="$99">

i have got parsing error in attributes values " 24" boot-cut". I was
reading attributes values from " to “. But in above case double
quotes(”) comes three times so my parser was not able to read it
properly.

How to solve the above problem?

Thanks in advance

Regards,
Martin

On Wed, Feb 27, 2008 at 1:03 AM, dare ruby [email protected]
wrote:

properly.

How to solve the above problem?

I’d suggest you require that "s within strings be escaped somehow.
Otherwise, the input is ambiguous - it might as well be ‘size = “24”’
followed by an unterminated ‘"boot cut’

martin

Thank you sebastian and martin. so its invalid to pass xml like that i
hope.
The attribute value should be like,

size=' 24" boot-cut '

or like,

size=" 24' boot-cut"

Is the above xml is valid. Please suggest a better way of inputs in
proper xml for above attributes.

regards,
Martin

dare ruby wrote:

Is the above xml is valid. Please suggest a better way of inputs in
proper xml for above attributes.

Yes, it’s valid, but I suggest a better way:

size=" 24" boot-cut"

Replacing " with its XML entity “. Any attribute value should be
processed to replace special XML characters (”’<>&) with their entity.

dare ruby wrote:

My parser was showing
parsing errors in case of input like,

  <product prod_name=“jean” size=" 24" boot-cut" price="$99">

Well, in case that the input is supposed to be XML, your parser was
right to
do so as the above is not valid.