我试图建立一个可以根据输入的内容动态创建xml的系统。我有一个总是相同的seleton,并且唯一需要动态创建的是formfields。因此,例如,我需要将$ testXML插入到我的$ writer XML中。这是我到目前为止所拥有的
use strict;
use warnings;
use XML::Writer;
my $test = XML::Writer->new(OUTPUT => 'self', DATA_MODE => 1, DATA_INDENT => 2, );
$test->startTag('FormField', name => 'CheckBox1');
$test->startTag('Value');
$test->characters('');
$test->endTag('Value');
$test->endTag('FormField');
my $testXML = $test->end();
插入
my $writer = XML::Writer->new(OUTPUT => 'self', DATA_MODE => 1, DATA_INDENT => 2, );
$writer->startTag('Section', name => 'FormSectionOne');
$writer->startTag('FormField', name => 'Person1');
$writer->startTag('Value');
$writer->characters('Bob Test');
$writer->endTag('Value');
$writer->endTag('FormField');
$testXML;
my $xml = $writer->end();
print $xml;
现在使用$ writer-> raw($ testXML);插入但格式有问题
<Section name="FormSectionOne">
<FormField name="Person1">
<Value>Bob Test</Value>
</FormField><FormField name="CheckBox1">
<Value>test</Value>
答案 0 :(得分:1)
my $writer = XML::Writer->new(
OUTPUT => 'self',
DATA_MODE => 1,
DATA_INDENT => 2,
UNSAFE => 1,
);
...
$writer->raw($testXML);
...