REXML -> attributes with single/double quotes

Discussion in 'Ruby' started by Stephan Kämper, Nov 14, 2005.

  1. Hi all,

    when I write a previously read XML using REXML, all attribute values are
    single quoted. Unfortunately the application I'm feeding that XML to
    (currently) can't cope with that.

    I tried to rad and understand the XML Standard, but couldn't find the
    exact place where it says, that both single and double quoted strings
    are allowed to delimit attribute values.
    If this the right place?


    [10] AttValue ::= '"' ([^<&"] | Reference)* '"'
    | "'" ([^<&'] | Reference)* "'"


    From: http://www.w3.org/TR/REC-xml/
    Section 2.3 "Common Syntactic Constructs"

    That seems to say that attributes are either delimited by single quotes
    or by double quotes.

    The easy way, would be to follow the advice Sean Russel gave on Tue, 24
    Jun 2003 10:02:02 +0900 in ruby-talk [74129], which was this:

    > In the meantime, if you really need this and are willing to hack the
    > sources, override REXML::Attribute::to_string(). Do something like
    > this in the application that generates the XML:
    >
    > REXML::Attribute.class_eval( %q^
    > def to_string
    > %Q[#@expanded_name="#{to_s().gsub(/"/, '&quot;')}"]
    > end
    > ^ )
    >
    > This will rewrite the method that is used to produce the XML fragment
    > for an Attribute.
    >


    That does indeed help. Thanks for answering a question I didn't have at
    that time (back in 2003). :)

    Is there a more elegant way to achieve this?


    Happy rubying and you're a great community out there.

    Stephan
     
    Stephan Kämper, Nov 14, 2005
    #1
    1. Advertising

  2. Stephan Kämper

    daz Guest

    Stephan Kämper wrote:
    > Hi all,
    >
    > when I write a previously read XML using REXML, all attribute values are
    > single quoted. Unfortunately the application I'm feeding that XML to
    > (currently) can't cope with that.


    Throw it away :)

    >
    > I tried to rad and understand the XML Standard, but couldn't find the
    > exact place where it says, that both single and double quoted strings
    > are allowed to delimit attribute values.
    > If this the right place?
    >
    >
    > [10] AttValue ::= '"' ([^<&"] | Reference)* '"'
    > | "'" ([^<&'] | Reference)* "'"
    >
    >
    > From: http://www.w3.org/TR/REC-xml/
    > Section 2.3 "Common Syntactic Constructs"
    >
    > That seems to say that attributes are either delimited by single quotes
    > or by double quotes.


    http://www.w3.org/TR/REC-xml/#sec-notation

    "string"

    matches a literal string matching that given inside the double quotes.

    'string'

    matches a literal string matching that given inside the single quotes.



    > >
    > > REXML::Attribute.class_eval( %q^
    > > def to_string
    > > %Q[#@expanded_name="#{to_s().gsub(/"/, '&quot;')}"]
    > > end
    > > ^ )
    > >

    >
    > Is there a more elegant way to achieve this?
    >


    I'd be disappointed if there wasn't -- sorry no help there, atm.


    daz
     
    daz, Nov 14, 2005
    #2
    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. Chris White

    Quotes/Double Quotes in Image Control

    Chris White, Sep 22, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    4,905
    Hermit Dave
    Sep 22, 2004
  2. Chris
    Replies:
    1
    Views:
    13,744
    Oisin
    Mar 24, 2006
  3. girish
    Replies:
    2
    Views:
    10,322
    Peter Flynn
    Aug 6, 2004
  4. Francis Hwang
    Replies:
    2
    Views:
    397
    Brian Candler
    Oct 21, 2004
  5. jOhn
    Replies:
    1
    Views:
    266
    Phlip
    Jan 29, 2008
Loading...

Share This Page