Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl LibXML-插入注释_Perl_Libxml2_Xml Libxml - Fatal编程技术网

Perl LibXML-插入注释

Perl LibXML-插入注释,perl,libxml2,xml-libxml,Perl,Libxml2,Xml Libxml,我使用的是XML::LibXML,我想添加一条注释,使注释位于标记之外。甚至可以把它放在标签外面吗?我已经试过了,孩子,插入之前,插入之后,没有区别 <JJ>junk</JJ> <!--My comment Here!--> # Code excerpt from within a foreach loop: my $elem = $dom->createElement("JJ"); my $txt_no

我使用的是XML::LibXML,我想添加一条注释,使注释位于标记之外。甚至可以把它放在标签外面吗?我已经试过了,孩子,插入之前,插入之后,没有区别

     <JJ>junk</JJ> <!--My comment Here!-->

     # Code excerpt from within a foreach loop:
     my $elem     = $dom->createElement("JJ");
     my $txt_node = $dom->createTextNode("junk");
     my $cmt      = $dom->createComment("My comment Here!");

     $elem->appendChild($txt_node);
     $b->appendChild($elem);
     $b->appendChild($frag);
     $elem->appendChild($cmt);

    # but it puts the comment between the tags ...
    <JJ>junk<!--My comment Here!--></JJ>
垃圾 #foreach循环中的代码摘录: my$elem=$dom->createElement(“JJ”); 我的$txt_节点=$dom->createTextNode(“垃圾”); my$cmt=$dom->createComment(“我的评论在这里!”); $elem->appendChild($txt\u节点); $b->appendChild($elem); $b->附加儿童($frag); $elem->appendChild($cmt); #但它将注释放在标签之间。。。 废旧物品
不要将注释节点附加到
$elem
,而是附加到父节点。例如,下面的脚本

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);
印刷品


不要将注释节点附加到
$elem
,而是附加到父节点。例如,下面的脚本

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);
印刷品