Take a look at: https://stackoverflow.com/questions/19411152/libxml-inserting-a-comment
use XML::LibXML; my $doc = XML::LibXML::Document->new;my $root = $doc->createElement("doc"); $doc->setDocumentElement($root); $root->appendChild($doc->createElement("JJ")); $root->appendChild($doc->createComment("comment"));print $doc->toString(1); So, maybe your comment needs an element to be a child of, not the root node itself. On Mon, Sep 10, 2018 at 6:50 AM John Cortland Morgan < johncortland.mor...@ericsson.com> wrote: > Hi, > > I'm trying to place a comment directly after the XML declaration using > XML::LibXML, > But cannot seem to manage, always receiving error: > > setDocumentElement: ELEMENT node required at .../LibXML.pm line 1393 > > What I would like: > > <?xml version="1.0" encoding="utf-8"> > <!-- test comment --> > <products> > <field>testing</field> > </products> > > My relevant code thus far: > > My $dom = XML::LibXML::Document->new( "1.0", "UTF-8"); > My $root = XML::LibXML::Comment->new( "test comment" ); > $dom->setDocumentElement($root); > > > Any help would be greatly appreciated. I'm kinda stuck with using > XML::LibXML though. > > John > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > > -- a Andy Bach, afb...@gmail.com 608 658-1890 cell 608 261-5738 wk