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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |