我有一个这样的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)。我看不出为什么,可以吗?我试着对代码发表评论以帮助理解发生了什么,但如果评论不正确,请纠正我。谢谢。
你能给你的意思是“原始RAWDATA”什么的例子吗?你的意思是像一个参考,“标志(0×814f5c4)”? – 2010-01-17 20:14:27
谢谢,我在问题中增加了更多细节。 – John 2010-01-17 20:17:27
您会注意到XML包含一个“rawData”标记。 'textContent'打印出这个节点和所有子节点的文本内容(不是属性) - 换句话说,它应该打印出'0.1123975676' – 2010-01-17 20:18:07