是否可以XML::LibXML
解析以下示例中显示的节点?我意识到我可能通过将 a 指定'*'
为节点名称的一部分来创建无效的 XML,如果有人能解释为什么它无效,我将不胜感激:
use strict;
use warnings;
use XML::LibXML;
my $doc = XML::LibXML->createDocument;
my $quirky = XML::LibXML::Element->new( 'YAK*' );
$quirky->appendText( 'Important Data' );
$doc->setDocumentElement( $quirky );
print $doc->toString; # <?xml version="1.0"?>
# <YAK*>Important Data</YAK*>
my $data = XML::LibXML
->new
->parse_string( $doc->toString );
输出:
<?xml version="1.0"?>
<YAK*>Important Data</YAK*>
:2: parser error : error parsing attribute name
<YAK*>Important Data</YAK*>
^
:2: parser error : attributes construct error
<YAK*>Important Data</YAK*>
^
:2: parser error : Couldn't find end of Start Tag YAK line 2
<YAK*>Important Data</YAK*>
^
:2: parser error : Extra content at the end of the document
<YAK*>Important Data</YAK*>
^