文獻順序是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