[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

REXML question

Pau Garcia i Quiles

10/28/2006 11:19:00 PM

Hello,

I am using REXML to create XML documents but I am facing a problem: I cannot
add XML childs.

I want to create a parent element with REXML, then add a bunch of XML as a
children (I already have that XML). I would like to do something like this:

xml = REXML::Element.new('parent')
xml.add_xml_element('<child><attrib1>value1</attrib1><attrib2>value2</attrib2></child>')

Then xml.to_s would output:
<parent><child><attrib1>value1</attrib1><attrib2>value2</attrib2></child></parent>

I have tried with REXML::Element#add_element, but it adds an extra '<' before
the child:
<parent><<child><attrib1>value1</attrib1><attrib2>value2</attrib2></child></parent>

Am I trying something impossible?

Thank you.

--
Pau Garcia i Quiles
http://www.e...
(Due to the amount of work, I usually need 10 days to answer)
1 Answer

Kalman Noel

10/29/2006 8:18:00 AM

0

Pau Garcia i Quiles:
> xml = REXML::Element.new('parent')
> xml.add_xml_element('<child><attrib1>value1</attrib1><attrib2>value2</attrib2></child>')
>
> Then xml.to_s would output:
> <parent><child><attrib1>value1</attrib1><attrib2>value2</attrib2></child></parent>

# »Element« for creating tags:
parent = REXML::Element.new('parent')
# »Document« for XML input:
child = REXML::Document.new('<child><attrib1>value1</attrib1></child>')

parent << child
parent.to_s

Kalman