ellis has asked for the wisdom of the Perl Monks concerning the following question:
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"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Question about XML::DOM::Lite
by NetWallah (Canon) on Aug 16, 2011 at 20:34 UTC | |
|
Re: Question about XML::DOM::Lite
by choroba (Cardinal) on Aug 19, 2011 at 14:16 UTC |