You are viewing a plain text version of this content. The canonical link for it is here.
Posted to p-dev@xerces.apache.org by Marco Valtas <ma...@mac.com> on 2002/04/17 21:39:04 UTC
Get elements values
How get elements values ?
I'm stuck on a Node that is nodeType = 1, meaning it's a Element type,
so if a try getNodeValue I get null, but if I try getNodeName I get
the right one. What i'm doing wrong?
Sample code:
my $xmlDocument->getDocument();
my $nodeList = $xmlDocument->getElementsByTagName("some_element");
my $node = $nodeList->item(0);
print $node->getNodeName(); print "this is my element name\n";
print $node->getNodeValue();print "this should by the value of it\n";
Marco.
--
#Marco Aurélio Valtas Cunha
#Laboratório de Bioinformática
#Hemocentro de Ribeirão Preto
#Faculdade de Medicina de Ribeirão Preto
#Universidade de São Paulo
#Tel 55 16 3963-9300 R: 9603
#homepage http://bit.fmrp.usp.br
#e-mail: mavcunha@mac.com
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org
Re: Get elements values
Posted by Fredrick Paul Eisele <ph...@netarx.com>.
Marco Valtas wrote:
> How get elements values ?
> I'm stuck on a Node that is nodeType = 1, meaning it's a Element type,
> so if a try getNodeValue I get null, but if I try getNodeName I get
> the right one. What i'm doing wrong?
>
> Sample code:
>
> my $xmlDocument->getDocument();
> my $nodeList = $xmlDocument->getElementsByTagName("some_element");
> my $node = $nodeList->item(0);
> print $node->getNodeName(); print "this is my element name\n";
> print $node->getNodeValue();print "this should by the value of it\n";
>
>
> Marco.
>
You are elements don't have values.
Elements contain other nodes which may have values.
Text nodes and Attribute nodes have values.
So you want something like...
sub get_element_value {
my $element = shift;
for (my $node = $element->getFirstChild; ! $node->isNull; $node =
$node->getNextSibling) {
next if ($node->getNodeType != $XML::Xerces::DOMParse::ELEMENT_NODE);
print $node->getNodeValue;
}
}
... or you can just use XML::Xerces::DOMParse::element_text( $element )
which
does, roughly, the same thing.
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org