I have this loop:
foreach my $node ($element->getChildNodes()) {}
Each $node represents a piece of XML of the form: <tag_name>Content</tag_name>
I want to extract the "Content" ie the character data between the start and end tags of each node in the loop above. There is only character data in each of these nodes.
My understanding of the docs is that the character data is stored in the only child node of the node representing the element. Hence I tried to extract it with:
my $child_nodes = $node->getChildNodes(); # get the child nodes my $child_node = $child_nodes->[0]; # get the first (only) child node my $content = $child_node->getData(); # get the content
but this dies with the error "Can't call method "getData" on an undefined value"
I'm sure this is simple, but I'm having one of those days and I just can't spot the error. Any suggestions? Thanks
In reply to Using XML::DOM to get the contents of an element by ezekiel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |