How to parse attributes in ruby?

Discussion in 'Ruby' started by dare ruby, Feb 27, 2008.

  1. dare ruby

    dare ruby Guest

    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
    --
    Posted via http://www.ruby-forum.com/.
    dare ruby, Feb 27, 2008
    #1
    1. Advertising

  2. On Wed, Feb 27, 2008 at 1:03 AM, dare ruby <> wrote:
    > 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?


    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
    Martin DeMello, Feb 27, 2008
    #2
    1. Advertising

  3. dare ruby wrote:
    > My parser was showing
    > parsing errors in case of input like,
    >
    > =C2=A0 =C2=A0 <product prod_name=3D"jean" size=3D" 24" boot-cut" price=3D=

    "$99">

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


    =2D-=20
    Jabber:
    ICQ: 205544826
    Sebastian Hungerecker, Feb 27, 2008
    #3
  4. dare ruby

    dare ruby Guest

    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
    --
    Posted via http://www.ruby-forum.com/.
    dare ruby, Feb 27, 2008
    #4
  5. dare ruby wrote:
    > 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.


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

    size=" 24&quot; boot-cut"

    Replacing " with its XML entity &quot;. Any attribute value should be
    processed to replace special XML characters ("'<>&) with their entity.

    --
    Michel Casabianca
    Michel Casabianca, Feb 27, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeremy Chapman
    Replies:
    3
    Views:
    2,472
    Raymond
    Feb 28, 2006
  2. Max
    Replies:
    1
    Views:
    478
    Joe Kesselman
    Sep 22, 2006
  3. Replies:
    19
    Views:
    1,121
    Daniel Vallstrom
    Mar 15, 2005
  4. Matteo
    Replies:
    2
    Views:
    357
    Peter Otten
    Jul 24, 2007
  5. 7stud --

    optparse: parse v. parse! ??

    7stud --, Feb 20, 2008, in forum: Ruby
    Replies:
    3
    Views:
    185
    7stud --
    Feb 20, 2008
Loading...

Share This Page