XML::LibXML and getting data from elements/nodes

From: Derrell Durrett (derrell.spam.durrett_at_xilinx.killer.com)
Date: 10/27/04

  • Next message: Tassilo v. Parseval: "Re: Namespace and comments on usefulness sought"
    Date: Tue, 26 Oct 2004 18:50:15 -0600
    
    

    With the code below, I get the following output:

    Use of uninitialized value in concatenation (.) or string at
    /home/durrett/proto line 36.
    Use of uninitialized value in concatenation (.) or string at
    /home/durrett/proto line 36.
    Use of uninitialized value in concatenation (.) or string at
    /home/durrett/proto line 36.
    Use of uninitialized value in concatenation (.) or string at
    /home/durrett/proto line 36.

      

      

      

      

    (yes, that's literally 14 empty lines, though some have spaces)

    I would expect, based on my (very simplistic) understanding of perldoc
    XML::LibXML::Node's 'getData' entry:
           getData
               If the node has any content (such as stored in a text node )
               it can get requested through this function.

    to see something more akin to
    "platform_id from tblPlatform"
    "platform_id"

    etc.

    Obviously, my expectations are amiss. But how would I get to these
    data? Also, it makes no sense to me that half of the nodes returned by
    $root->getChildNodes give 'text' as their name (from a debugger session
    of the same code):

      DB<5> x map {$ARG->getName} $root->getChildNodes
    0 'text'
    1 'ibom-for-each'
    2 'text'
    3 'platform'
    4 'text'
    5 'ibom-next'
    6 'text'
    7 'installDrops'
    8 'text'

    Why is this the case?

    I'd gladly read a manual, if someone can please point me to one that is
    more expansive than the perldoc for XML:LibXML::Node.

    Thanks,

    Derrell
    __CODE__
    #! /tools/xgs/perl/5.8.5/bin/perl

    # External modules
    use strict;
    use warnings;
    use English;

    use XML::LibXML;

    # Create a parser object
    my $XML_parser = XML::LibXML->new();

    my $xml_piece = <<'EOXML';
    <?xml version="1.0" encoding="ISO-8859-1"?>

    <image
        image_id="tblImage.image_id"
        imageName="tblImage.imageName"
        installMode="tblImage.installMode"
    >
       <ibom-for-each>"platform_id from tblPlatform"</ibom-for-each>
       <platform platDesc="tblPlatform.platform">
       </platform>
       <ibom-next>"platform_id"</ibom-next>
       <installDrops>
       <ibom-for-each>"drop_id from tblInstallDrops where
    install_id=$install"</ibom-for-each>
       <ibom-next>"drop_id"</ibom-next>
       </installDrops>
    </image>
    EOXML

    # No default attributes.
    $XML_parser->complete_attributes(0);
    my $doc = $XML_parser->parse_string( $xml_piece );
    my $root = $doc->getDocumentElement;
    print map {"$ARG\n"} map {$ARG->getData} $root->getChildNodes;

    -- 
    Derrell Durrett
    Xilinx, Inc. / Software Productivity Tools
    Longmont, Colorado / 720.652.3843
    ***remove bits about .processed meats and .death from e-mail to reply
    

  • Next message: Tassilo v. Parseval: "Re: Namespace and comments on usefulness sought"

    Relevant Pages

    • Re: syntax...
      ... B&D on the part of the language designer. ... probably handle concatenation of string literals by itself, ... bitwise XOR, or if not that, then exponentiation.) ...
      (comp.lang.misc)
    • Bugs in the Module::Dependency
      ... Manifying blib/man1/pmd_indexer.plx.1 ... Use of uninitialized value in concatenation or string at ... # Failed test in t/04grapher.t at line 81. ...
      (perl.dbi.users)
    • Too Few Parameters Problem w/Query
      ... I am trying to run a concatenate function in a query and I'm having a ... Domain As String, _ ... ' Description: A generic "concatenation" routine. ... Dim strConcatenate As String ...
      (microsoft.public.access.gettingstarted)
    • Re: Coding Horrors, Cargo Cult Programming, and other Ghoulish Things
      ... In a complexity analysis, every operation contributes to the complexity whether or not it's considered time consuming. ... The concatenation of many involves a loop, so you have the loop complexity for whatever constant-time overhead happens before or after each concatenation operation. ... It's slow in .Net because of string immutability, GC and the lack of an aggregated '+' operator. ... In native Delphi s2+s3+s4 will be performed by a single function call, which will be able to produce the result string in one step. ...
      (borland.public.delphi.non-technical)
    • Re: a nice little perl utility
      ... Use of uninitialized value in concatenation or string at jabba5.pl ... How did this have to do with the print statement? ... # Fetch overview information for the articles ...
      (comp.lang.perl.misc)