getNodeValue Problem -Xerces Perl

Waseem

Usenet Archive
Joined
Jul 6, 2004
Messages
3
Reaction score
0
Hi

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;
$DOM->setErrorHandler($error_handler);
$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" xsi:noNamespaceSchemaLocation='lr.xsd'> <roomref>ccccccccccccccc</roomref> <roomday>2004-06-30Z</roomday> <roomprice>229.00</roomprice> </room>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,245
Members
248,133
Latest member
DujonT

Latest Threads

Top