I am using the cpan XML-DOM-Lite library version 0.08 to create an xml document. The following is the code and output.

my $dc = XML::DOM::Lite::Document->new(); my $root = $dc->createElement("xml"); my $elem = $dc->createElement("A"); $elem->setAttribute("B", "C"); $root->appendChild($elem); $dc->appendChild($root); print $dc->xml(); Output: ======= <xml> <A B="C" /> </xml>

Instead of having "B" defined as an attribute, I want "B" to be defined as a separate tagname, with "C" defined as a text. Is this xml output possible?

Desired output: =============== <xml> <A><B> C </B></A> </xml>

I made the following changes to the code, and it returned an error message.

my $dc = XML::DOM::Lite::Document->new(); my $root = $dc->createElement("xml"); my $elem = $dc->createElement("A"); my $elem2 = $dc->createElement("B"); # Added $elem2->createTextNode("C"); # Added $elem->appendChild($elem2); # Added $root->appendChild($elem); $dc->appendChild($root);

Error message: Can't locate object method "createTextNode" via package "XML::DOM::Lite::Node"


In reply to Question about XML::DOM::Lite by ellis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.