# Double Quotes in XML

**URL:** <https://www.ruby-forum.com/t/double-quotes-in-xml/55205>\
**Category:** Ruby\
**Created:** [March 17, 2006, 9:35pm UTC](https://www.ruby-forum.com/t/double-quotes-in-xml/55205 "2006-03-17T21:35:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gparsons](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b487fb/32.png) [@gparsons](https://www.ruby-forum.com/u/gparsons)\
**Post date:** [March 17, 2006, 9:35pm UTC](https://www.ruby-forum.com/t/double-quotes-in-xml/55205/1 "2006-03-17T21:35:39Z")

</div>

I’m trying to do something similar to the following:

\<?xml version="1.0" encoding="utf-8"?\> Foo must equal "bar". `Foo = "bar"`

I’m reading the actual rules and descriptions in from a giant file and  
when i spit it back out into an xml file i get errors involving the  
quotes around bar. Looking at examples that should be working i notice  
there’s a difference between the quotes (if this will show up in groups  
it’s: " vs " ). I’m by no means an xml expert (or even novice) so i  
may just be missing something here, but it seems like it’s something to  
do with the encodings maybe? Anyone have any suggestions?

- Geoff

---

<div class="post-metadata">

**Author:** ![gparsons](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b487fb/32.png) [@gparsons](https://www.ruby-forum.com/u/gparsons)\
**Post date:** [March 17, 2006, 9:50pm UTC](https://www.ruby-forum.com/t/double-quotes-in-xml/55205/2 "2006-03-17T21:50:48Z")

</div>

On 3/17/06, gparsons [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m reading the actual rules and descriptions in from a giant file and  
> when i spit it back out into an xml file i get errors involving the  
> quotes around bar. Looking at examples that should be working i notice  
> there’s a difference between the quotes (if this will show up in groups  
> it’s: " vs " ). I’m by no means an xml expert (or even novice) so i  
> may just be missing something here, but it seems like it’s something to  
> do with the encodings maybe? Anyone have any suggestions?

You need to do one of the following.  
`
bar
Foo="bar"`

`
I prefer the first option listed above.
On another note, I don’t think it’s typical to use uppercase the way you
are.
I’d do it like this.
`

---

<div class="post-metadata">

**Author:** ![gparsons](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b487fb/32.png) [@gparsons](https://www.ruby-forum.com/u/gparsons)\
**Post date:** [March 17, 2006, 10:30pm UTC](https://www.ruby-forum.com/t/double-quotes-in-xml/55205/3 "2006-03-17T22:30:20Z")

</div>

Unfortunately i don’t have much control over the markup (i’m not even  
sure the program that is reading this in is expecting valid xml…  
sigh). turns out it was a problem with what i was reading in having  
some funky stuff going on.

---

<div class="post-metadata">

**Author:** ![gparsons](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b487fb/32.png) [@gparsons](https://www.ruby-forum.com/u/gparsons)\
**Post date:** [March 18, 2006, 1:11am UTC](https://www.ruby-forum.com/t/double-quotes-in-xml/55205/4 "2006-03-18T01:11:05Z")

</div>

On Mar 17, 2006, at 3:33 PM, gparsons wrote:

> I’m trying to do something similar to the following:
> 
> \<?xml version="1.0" encoding="utf-8"?\> Foo must equal "bar". `Foo = "bar"`

This is well-formed XML.

(BTW, there is nothing wrong with the use of caps in the element  
names, maybe slightly unusual but that’s all – just don’t forget  
that XML is case sensitive)

> do with the encodings maybe? Anyone have any suggestions?  
> What is giving you the errors? If I read you correctly, it is when  
> you are writing the XML, so it isn’t a parser giving you trouble.

Cheers,  
Bob

> - Geoff

* * *

Bob H. – blogs at \<[http://www.recursive.ca/](http://www.recursive.ca/)  
hutch/\>  
Recursive Design Inc. – [http://www.recursive.ca/](http://www.recursive.ca/)  
Raconteur – [http://www.raconteur.info/](http://www.raconteur.info/)  
xampl for Ruby – [http://rubyforge.org/projects/xampl/](http://rubyforge.org/projects/xampl/)

---

<div class="post-metadata">

**Author:** ![gparsons](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b487fb/32.png) [@gparsons](https://www.ruby-forum.com/u/gparsons)\
**Post date:** [March 18, 2006, 12:00pm UTC](https://www.ruby-forum.com/t/double-quotes-in-xml/55205/5 "2006-03-18T12:00:37Z")

</div>

On Mar 17, 2006, at 7:22 PM, Mark V. wrote:

> > > ```
> > > <Code>Foo = "bar"</Code>
> > > 
> > > ```
> > 
> > This is well-formed XML.
> 
> I think it’s not well-formed because the Code element contains text  
> with unescaped double-quotes. If you change them to " then it’s  
> well-formed.

It isn’t really a matter of opinion, and you are nowhere near lazy  
enough 🙂 Run it through a validator. Both rxp and xmllint believe  
that it is OK. That is not to say that it wouldn’t be better to  
escape those three characters ( quot, apos, and gt – you _must_  
escape lt and amp) – there’s a lot of buggy software out there, and  
a little prevention can save you lots of trouble.  
.

Cheers,  
Bob

> –  
> R. Mark V.  
> Object Computing, Inc.

* * *

Bob H. – blogs at \<[http://www.recursive.ca/](http://www.recursive.ca/)  
hutch/\>  
Recursive Design Inc. – [http://www.recursive.ca/](http://www.recursive.ca/)  
Raconteur – [http://www.raconteur.info/](http://www.raconteur.info/)  
xampl for Ruby – [http://rubyforge.org/projects/xampl/](http://rubyforge.org/projects/xampl/)

---

<div class="post-metadata">

**Author:** ![gparsons](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b487fb/32.png) [@gparsons](https://www.ruby-forum.com/u/gparsons)\
**Post date:** [March 18, 2006, 1:23am UTC](https://www.ruby-forum.com/t/double-quotes-in-xml/55205/6 "2006-03-18T01:23:08Z")

</div>

On 3/17/06, Bob H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 
> 
> This is well-formed XML.

I think it’s not well-formed because the Code element contains text  
with unescaped double-quotes. If you change them to " then it’s  
well-formed.
