xerces perl getNodeValue problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Waseem

    #1

    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::A bstractDOMParse r::Val_Always;

    ### set new parser
    my $DOM = XML::Xerces::Xe rcesDOMParser->new();
    $sc = 'lr.xsd';
    $DOM->setValidationS cheme ($sc);
    $DOM->setDoNamespace s (1);
    $DOM->setDoSchema (1);
    $file = 'lr.xml';
    $error_handler = XML::Xerces::Pe rlErrorHandler->new();
    $DOM->setErrorHandle r($error_handle r);
    $d = $DOM->parse($file) ;
    XML::Xerces::er ror($@) if $@;
    $doc = $DOM->getDocument( );
    $root = $doc->getDocumentEle ment();
    $filter = MyNodeFilter->new();
    $what = $XML::Xerces::D OMNodeFilter::S HOW_ALL;
    $walker = $doc->createTreeWalk er($root,$what, $filter,1);
    XML::Xerces::er ror($@) if $@;
    $node = $walker->getCurrentNode ();
    #$cd = $cn->getFirstChild( );

    if ($node->hasChildNodes( )) {
    my $text;
    foreach my $child ($node->getChildNode s) {
    if ($child->getNodeType ne
    $XML::Xerces::D OMNode::ELEMENT _NODE) {
    print "sda";
    print $child->getNodeValue() ;

    }




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

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



    # $v = $child-> getElementsByTa gName($k);
    # print $v;
    #}
    ## if $child->isa('XML::Xerc es::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:noNamespace SchemaLocation= 'lr.xsd'>
    <roomref>cccccc ccccccccc</roomref>
    <roomday>2004-06-30Z</roomday>
    <roomprice>229. 00</roomprice>
    </room>
    ------------------------------------------------------------------------------



    Waseem
Working...