# REXML -\> attributes with single/double quotes

**URL:** <https://www.ruby-forum.com/t/rexml-attributes-with-single-double-quotes/47880>\
**Category:** Ruby\
**Created:** [November 14, 2005, 8:53pm UTC](https://www.ruby-forum.com/t/rexml-attributes-with-single-double-quotes/47880 "2005-11-14T20:53:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephan.Kaemper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c4cdca/32.png) [@Stephan.Kaemper](https://www.ruby-forum.com/u/Stephan.Kaemper)\
**Post date:** [November 14, 2005, 8:53pm UTC](https://www.ruby-forum.com/t/rexml-attributes-with-single-double-quotes/47880/1 "2005-11-14T20:53:02Z")

</div>

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/](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:

> 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

---

<div class="post-metadata">

**Author:** ![Stephan.Kaemper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c4cdca/32.png) [@Stephan.Kaemper](https://www.ruby-forum.com/u/Stephan.Kaemper)\
**Post date:** [November 14, 2005, 9:14pm UTC](https://www.ruby-forum.com/t/rexml-attributes-with-single-double-quotes/47880/2 "2005-11-14T21:14:06Z")

</div>

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 🙂

> From: [Extensible Markup Language (XML) 1.0 (Fifth Edition)](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](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(/”/, ‘"’)}"]  
> > end  
> > ^ )
> 
> Is there a more elegant way to achieve this?

I’d be disappointed if there wasn’t – sorry no help there, atm.

daz
