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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to