我有以下 XML,我想通过 Perl 脚本创建和填充数据。在这个 XML 中,我有一些属性的集合类型,即 primarySiteCollection。
如何动态填充和生成“primarySiteCollection”节点。在此 XML 中,primarySiteCollection 包含 3 个组织站点,但可以有 1 个或多个。
<TumorDetails>
<personUpi>String</personUpi>
<ageAtDiagnosis>3.14159E0</ageAtDiagnosis>
<biopsyPathologyReportSummary>String</biopsyPathologyReportSummary>
<primarySiteCollection>
<tissueSite>
<description>String1</description>
<name>String1</name>
</tissueSite>
<tissueSite>
<description>String2</description>
<name>String2</name>
</tissueSite>
<tissueSite>
<description>String3</description>
<name>String3</name>
</tissueSite>
</primarySiteCollection>
</TumorDetails>
这是我的 Perl 脚本。我想动态生成包含属性集合类型的节点。
use strict;
use warnings;
use XML::Compile::Schema;
my $node = {
personUpi => 'String',
ageAtDiagnosis => '3.14159E0',
biopsyPathologyReportSummary => 'String',
primarySiteCollection => {
tissueSite => {
description => 'String',
name => 'String',
},
},
};
my $schema = XML::Compile::Schema->new('sample.xsd');
my $writer = $schema->compile(WRITER => 'TumorDetails');
my $doc = XML::LibXML::Document->new(q(1.0), q(UTF-8));
print $writer->($doc, $node)->toString;