How to eliminate hash tag when to_xml is used.

S

Song Choe

# help

Hi=2C everyone=2C=20


I have a hash obj and when converted to xml using to_xml the <hash></hash> =
tag appears like the following

<?xml version=3D"1.0" encoding=3D"UTF-8"?>
<hash>
<step1>
...
</hash>

I want to get rid of that <hash> so that it is just
<?xml version=3D"1.0" encoding=3D"UTF-8"?>
<step1>
...
</step1>

Please help. Thank you=2C=20

Song=2C




_________________________________________________________________
Windows Live=99 SkyDrive=99: Get 25 GB of free online storage. =20
http://windowslive.com/online/skydrive?ocid=3DTXT_TAGLM_WL_skydrive_042009=
 
M

Mark Thomas

# help

Hi, everyone,

I have a hash obj and when converted to xml using to_xml the <hash></hash> tag appears like the following

<?xml version="1.0" encoding="UTF-8"?>
<hash>
  <step1>
..
</hash>

I want to get rid of that <hash> so that it is just
<?xml version="1.0" encoding="UTF-8"?>
  <step1>
..
</step1>

Since you want the xml declaration, I assume you want a valid XML
document. A valid XML document must have exactly one root element. You
cannot remove the root, because then if your hash had more than one
entry it would produce multiple roots and thus invalid XML.

You can change the name of the element, however:
hash.to_xml({:root => 'steps'})

-- Mark.
 
S

Song Choe

Thank you!!!
THis helps!!

Song=2C
Date: Wed=2C 29 Apr 2009 10:30:05 +0900
From: (e-mail address removed)
Subject: Re: How to eliminate hash tag when to_xml is used.
To: (e-mail address removed)
=20

=20
Since you want the xml declaration=2C I assume you want a valid XML
document. A valid XML document must have exactly one root element. You
cannot remove the root=2C because then if your hash had more than one
entry it would produce multiple roots and thus invalid XML.
=20
You can change the name of the element=2C however:
hash.to_xml({:root =3D> 'steps'})
=20
-- Mark.
=20

_________________________________________________________________
Windows Live=99 Hotmail=AE:=85more than just e-mail.
http://windowslive.com/online/hotmail?ocid=3DTXT_TAGLM_WL_HM_more_042009=
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top