getNodeValue Problem -Xerces Perl

Discussion in 'Perl Misc' started by Waseem, Jul 6, 2004.

  1. Waseem

    Waseem Guest

    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
    Waseem, Jul 6, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Manuel
    Replies:
    0
    Views:
    541
    Manuel
    Aug 28, 2003
  2. Peter Chatterton

    DOM Problem with getNodeValue()

    Peter Chatterton, Oct 19, 2003, in forum: Java
    Replies:
    9
    Views:
    2,786
    Peter Chatterton
    Oct 20, 2003
  3. David
    Replies:
    4
    Views:
    3,777
    Toni Uusitalo
    Dec 17, 2003
  4. Bernard Kufluk

    problem with getNodeValue

    Bernard Kufluk, Apr 21, 2004, in forum: XML
    Replies:
    1
    Views:
    501
    Bernard Kufluk
    Apr 21, 2004
  5. Waseem
    Replies:
    0
    Views:
    831
    Waseem
    Jul 6, 2004
Loading...

Share This Page