|
Posted by Derrell Durrett on October 26, 2004, 7:50 pm
Please log in for more thread options
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 $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 map $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
|
|
Posted by Brian McCauley on October 27, 2004, 6:39 pm
Please log in for more thread options
Derrell Durrett wrote:
[ with this data ]
> <?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>
[ I do ]
> my $doc = $XML_parser->parse_string( $xml_piece );
> my $root = $doc->getDocumentElement;
> print map map $root->getChildNodes;
[ I get ]
> Use of uninitialized value in concatenation (.) or string
> I would expect to see something more akin to
> "platform_id from tblPlatform"
> "platform_id"
> DB<5> x map $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?
getChildNodes gets only the immediate children.
The child nodes of the the root element are those element nodes listed
above and the whitespace text nodes that separate them. A text node
doesn't really have any name so it returns 'text'.
The text you are looking for is not in children of the root node but
rather in grandchild text nodes.
> 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.
The textContent() method (the one you are looking for) is documented there.
However the manuals for XML::LibXML are rather terses as they do assume
some familarity with DOM.
http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/
|
|
Posted by Derrell Durrett on October 29, 2004, 12:23 pm
Please log in for more thread options Brian McCauley wrote:
> Derrell Durrett wrote:
>
>> 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.
>
> The textContent() method (the one you are looking for) is documented
> there.
It's not exactly what I wanted. It gets *all* of the text under a given
node, rather than only the text directly attached to *only this node.*
Am I the only person who thinks this would be more valuable than all
text under this node?
But it was enough of a clue to help me understand what was going on
here, counter-intuitive though the interfaces may be (well, to me, anyway)
> However the manuals for XML::LibXML are rather terses as they do
> assume some familarity with DOM.
> http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/
Thanks for pointing me to this. I'd been over it before, but without
constant cross-reference to a module and examples (found elsewhere:
http://grouper.ieee.org/xmltwig/article/ways_to_rome_2/), I couldn't
make heads or tails of why things are the way they are.
Thanks again,
Derrell
--
Derrell Durrett
Xilinx, Inc. / Software Productivity Tools
Longmont, Colorado / 720.652.3843
***remove bits about .processed meats and .death from e-mail to reply
|
|
Posted by Brian McCauley on October 30, 2004, 6:59 pm
Please log in for more thread options
Derrell Durrett wrote:
> Brian McCauley wrote:
>
>> Derrell Durrett wrote:
>>
>>> 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.
>>
>>
>> The textContent() method (the one you are looking for) is documented
>> there.
>
>
> It's not exactly what I wanted. It gets *all* of the text under a given
> node, rather than only the text directly attached to *only this node.*
> Am I the only person who thinks this would be more valuable than all
> text under this node?
Probably, yes.
In any typical XML document the content of an element is either:
1) Nothing
2) Further elements to a structured way eg like you always have
<body> and <head> under <html>
3) A single text child node.
4) A mixture of text nodes and element nodes representing text
mark-up or text with embeded objects.
It would be poor design of an XML schema to have (significant) text
interspersed with elements that are not representing text mark-up or
objects embedded within the text.
|
|
Posted by Derrell Durrett on November 3, 2004, 9:44 am
Please log in for more thread options Brian McCauley wrote:
>
>
> Derrell Durrett wrote:
>
>> Brian McCauley wrote:
>>
>>> Derrell Durrett wrote:
>>>
>>>> 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.
>>>
>>>
>>>
>>> The textContent() method (the one you are looking for) is documented
>>> there.
>>
>> It's not exactly what I wanted. It gets *all* of the text under a
>> given node, rather than only the text directly attached to *only this
>> node.* Am I the only person who thinks this would be more valuable
>> than all text under this node?
>
>
> Probably, yes.
>
> In any typical XML document the content of an element is either:
> <... deleted>
> 4) A mixture of text nodes and element nodes representing text
> mark-up or text with embeded objects.
>
> It would be poor design of an XML schema to have (significant) text
> interspersed with elements that are not representing text mark-up or
> objects embedded within the text.
Ah. That explains the fact that virtually of the text elements in
question are empty strings.
Thanks again,
Derrell
--
Derrell Durrett
Xilinx, Inc. / Software Productivity Tools
Longmont, Colorado / 720.652.3843
***remove bits about .processed meats and .death from e-mail to reply
|
| Similar Threads | Posted | | data structure from XML::LibXML | October 6, 2004, 6:22 pm |
| Possible bug in XML:LibXML | December 16, 2007, 6:22 am |
| LibXML and DTD's | July 5, 2007, 1:26 pm |
| Questions about XML:LibXML | December 16, 2007, 6:22 am |
| compile problems with XML::LibXML | December 22, 2004, 5:41 pm |
| problems with installation of XML::LibXML | June 7, 2005, 10:30 am |
| namespace declarations in LibXML | April 15, 2006, 12:48 am |
| LibXML "Undefined namespace prefix" | July 2, 2007, 5:42 pm |
| use DBI - how to properly get the data out | October 15, 2004, 1:02 pm |
| Averaging data | September 27, 2005, 9:47 pm |
|