473,407 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

xerces perl getNodeValue problem

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>
------------------------------------------------------------------------------

Waseem
Jul 20 '05 #1
0 3060

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Thomas | last post by:
hi, i upgraded my perl from 5.6/5.6.1 to 5.8 and encounter that xerces writes an xml file with iso-8859-1 instead of utf8 there is an unsolved problem of a false header (xerces writes utf-16...
4
by: David | last post by:
Hello , I'm trying to parse an XML document a get spicific tags such as email in the code below. I'm using xerces 2.4. However I don't manage to get the value for the email. Can anybody help. ...
0
by: Ralf Höppner | last post by:
I'm using xerces-c++ 2.4.0 and am testing some functions of it. How can I print the name or the value of a node to console ? I tried: const XMLCh* test=node->getNodeValue(); but it seems to...
0
by: Dale Gerdemann | last post by:
I've been trying to use DOM level 3 with xerces-2_6_2. There's a sample called samples/DOM3.java, but I've had trouble with compilation. I've downloaded Xerces-J-bin.2.6.2 and...
2
by: MBR | last post by:
Problem with xerces and C++ Hi, I try the sample from the xerces homepage http://xml.apache.org/xerces-c/program-dom.html, take the iterator and step through the tree: for (DOMNode*...
2
by: MBR | last post by:
Help! I am using xerces with C++ and want to read the following simple file: <?xml version="1.0"?> <pets> <pet> <name>Tilly</name> <age>14</age> <type>cat</type>
4
by: MBR | last post by:
Help! Does anybody know a simple example how to use xerces (http://xml.apache.org) with C++ to parse a simple xml file, go from node to node and read the data in the nodes? Thanks, Matthias
1
by: Matthias Braun | last post by:
Hilfe! Ich habe mir eine Xerces C++ Routine geschrieben, die alle Dokumente des XML-Trees parst. Die folgende rekursive Funktion funktioniert allerdings nicht 100%. Wer kann helfen? Danke,...
3
by: landoao | last post by:
I have found as following function. It must returns outtext but I don't know about C++ and Xerces-C++ library any more. who can execute this function on C++ and returm me input XML file and Output...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.