我有一个这样的 XML 文件:
<wave waveID="1">
<well wellID="1" wellName="A1">
<oneDataSet>
<rawData>0.1123975676</rawData>
</oneDataSet>
<well>
我正在尝试使用以下代码打印出 wellName 属性:
my @n1 = $xc->findnodes('//ns:wave[@waveID="1"]');
# so @n1 is an array of nodes with the waveID 1
# Above you are searching from the root of the tree,
# for element wave, with attribute waveID set to 1.
foreach $nod1 (@n1) {
# $nod1 is the name of the iterator,
# which iterates through the array @n1 of node values.
my @wellNames = $nod1->getElementsByTagName('well'); #element inside the tree.
# print out the wellNames :
foreach $well_name (@wellNames) {
print $well_name->textContent;
print "\n";
}
但我没有打印出 wellName,而是打印出 rawData 值(例如 0.1123975676)。我不明白为什么,你能吗?我试图评论代码以帮助理解发生了什么,但如果评论不正确,请纠正我。谢谢。