文献顺序是defined作为
有一个排序,文档顺序,所有文档中的对应于所述顺序的节点上限定的其中每个节点的XML表示的第一个字符在扩展一般实体之后出现在文档的XML表示中。因此,根节点将成为第一个节点。元素节点出现在他们的子女面前因此,文档顺序命令元素节点按XML中的起始标签的出现顺序(在扩展实体之后)。
换句话说,事情发生在XML文档中的顺序。XML::XPath模块按文件顺序生成结果。例如:
#! /usr/bin/perl
use warnings;
use strict;
use XML::XPath;
my $entity_template = "/Entities"
. "/Entity"
. "[EntityName='!!NAME!!']"
;
my $tables_path = join "|" =>
qw(./Tables/DataTables/DataTable
./Tables/OtherTables/OtherTable);
my $xp = XML::XPath->new(ioref => *DATA);
foreach my $ename (qw/ foo bar /) {
print "$ename:\n";
(my $path = $entity_template) =~ s/!!NAME!!/$ename/g;
foreach my $n ($xp->findnodes($path)) {
foreach my $t ($xp->findnodes($tables_path, $n)) {
print $t->toString, "\n";
}
}
}
__DATA__
为<Entity>
元件,其中每个具有<ElementName>
孩子其string-value是选择的实体名称的第一个表达式搜索。从那里,我们寻找<DataTable>
或<OtherTable>
。
鉴于
<Entities>
<Entity>
<EntityName>foo</EntityName>
<EntityType>type1</EntityType>
<Tables>
<DataTables>
<DataTable>1</DataTable>
<DataTable>2</DataTable>
</DataTables>
<OtherTables>
<OtherTable>3</OtherTable>
<OtherTable>4</OtherTable>
</OtherTables>
</Tables>
</Entity>
<Entity>
<EntityName>bar</EntityName>
<EntityType>type2</EntityType>
<Tables>
<DataTables>
<DataTable>5</DataTable>
<DataTable>6</DataTable>
</DataTables>
<OtherTables>
<OtherTable>7</OtherTable>
<OtherTable>8</OtherTable>
</OtherTables>
</Tables>
</Entity>
</Entities>
输出输入是
foo:
<DataTable>1</DataTable>
<DataTable>2</DataTable>
<OtherTable>3</OtherTable>
<OtherTable>4</OtherTable>
bar:
<DataTable>5</DataTable>
<DataTable>6</DataTable>
<OtherTable>7</OtherTable>
<OtherTable>8</OtherTable>
提取字符串值(下称“内文”),改变$tables_path
到
my $tables_path = "./Tables/DataTables/DataTable/text() |
./Tables/OtherTables/OtherTable/text()";
是,这是重复的 - 因为XML :: XPath实现了XPath 1.0。
输出:
foo:
1
2
3
4
bar:
5
6
7
8
就这么你知道,XML没有这样设置。如果你想要真正的元素排序,最好有一个名为“order”的属性填充顺序值。 – vol7ron 2010-09-06 12:49:15