REXML question

Discussion in 'Ruby' started by Pau Garcia i Quiles, Oct 29, 2006.

  1. --nextPart44723385.ftLTCzSWWr
    Content-Type: text/plain;
    charset="iso-8859-15"
    Content-Transfer-Encoding: quoted-printable
    Content-Disposition: inline

    Hello,

    I am using REXML to create XML documents but I am facing a problem: I canno=
    t=20
    add XML childs.

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

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

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

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

    Am I trying something impossible?

    Thank you.

    =2D-=20
    Pau Garcia i Quiles
    http://www.elpauer.org
    (Due to the amount of work, I usually need 10 days to answer)

    --nextPart44723385.ftLTCzSWWr
    Content-Type: application/pgp-signature

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.2.2 (GNU/Linux)

    iD8DBQBFQ+Vc/DzYv9iGJzsRAmo+AKC8JhIm0/W/H8eoCyxNlBs1cX4PjgCggSE0
    KJaQCNaK/6KOUH1E2i8pVX0=
    =1c/1
    -----END PGP SIGNATURE-----

    --nextPart44723385.ftLTCzSWWr--
     
    Pau Garcia i Quiles, Oct 29, 2006
    #1
    1. Advertising

  2. Pau Garcia i Quiles

    Kalman Noel Guest

    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
     
    Kalman Noel, Oct 29, 2006
    #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. Damphyr
    Replies:
    2
    Views:
    163
    Damphyr
    Jul 16, 2003
  2. Ralph Mason
    Replies:
    2
    Views:
    103
    Ralph Mason
    Jan 13, 2004
  3. Han Holl

    Rexml xpath question

    Han Holl, Feb 22, 2004, in forum: Ruby
    Replies:
    7
    Views:
    157
    Han Holl
    Mar 6, 2004
  4. Daniel Berger

    rexml error - REXML::Validation

    Daniel Berger, Oct 12, 2004, in forum: Ruby
    Replies:
    2
    Views:
    168
    Henrik Horneber
    Oct 12, 2004
  5. Phlip
    Replies:
    0
    Views:
    162
    Phlip
    Jan 15, 2008
Loading...

Share This Page