470,871 Members | 1,702 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,871 developers. It's quick & easy.

xerces perl getNodeValue problem


I have looked and tried everything and i still cant sort this out i
have no idea why this wont work

I am using Xerces Perl on Windows and Debian to try this and it wont
work on both of them.

Basically i am tryin to do simple tree transversale and get the node
values out

I now understand that evetything in DOM is a node including the actual
element values etc so i am using the code below , part done myself
part copied from the examples in the /t dir.

I dont get any values from this code, all i get are blanks and thats
it, if i do getNodeName instead i get "#text". From the commented out
code below this it shows i have tried many different things. I even
tried to copy the code in DOM2Hash.pl but i couldt get it to work for
my code.

Someone must have an answer.

----------------------------- code
use XML::Xerces;
use Getopt::Long;
use Benchmark;
package MyNodeFilter;
use vars qw(@ISA);
@ISA = qw(XML::Xerces::PerlNodeFilter);
$validate = $XML::Xerces::AbstractDOMParser::Val_Always;

### set new parser
my $DOM = XML::Xerces::XercesDOMParser->new();
$sc = 'lr.xsd';
$DOM->setValidationScheme ($sc);
$DOM->setDoNamespaces (1);
$DOM->setDoSchema (1);
$file = 'lr.xml';
$error_handler = XML::Xerces::PerlErrorHandler->new();
$d = $DOM->parse($file);
XML::Xerces::error($@) if $@;
$doc = $DOM->getDocument();
$root = $doc->getDocumentElement();
$filter = MyNodeFilter->new();
$what = $XML::Xerces::DOMNodeFilter::SHOW_ALL;
$walker = $doc->createTreeWalker($root,$what,$filter,1);
XML::Xerces::error($@) if $@;
$node = $walker->getCurrentNode();
#$cd = $cn->getFirstChild();

if ($node->hasChildNodes()) {
my $text;
foreach my $child ($node->getChildNodes) {
if ($child->getNodeType ne
$XML::Xerces::DOMNode::ELEMENT_NODE) {
print "sda";
print $child->getNodeValue();


# if ($child->isa('XML::Xerces::DOMElement')) {
# $k .= $child->getNodeValue();

# }
# if ($child->isa('XML::Xerces::DOMText')) {
# print "asd";
# print $k;
# $new{text} = $k;
# }

# $v = $child-> getElementsByTagName($k);
# print $v;
## if $child->isa('XML::Xerces::DOMText');
# print $text;
# $return->{text} = $text
# if $text !~ /^\s*$/;


--------------------------------- lr.xml
<?xml version="1.0"?>
<room xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

Jul 20 '05 #1
0 2919

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Thomas | last post: by
reply views Thread by Ralf Höppner | last post: by
reply views Thread by Dale Gerdemann | last post: by
2 posts views Thread by MBR | last post: by
2 posts views Thread by MBR | last post: by
4 posts views Thread by MBR | last post: by
1 post views Thread by Matthias Braun | last post: by
3 posts views Thread by landoao | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.