08-29-2008
xml-parser with perl
Hello
I want to write an xml- parser with perl an i use the libary XML::LibXML.
I have a problem with the command getElementsByTagName.
If there is an empty tag, the getElementsByTagName method returns a NodeList of length zero.
how can i check if this is a nodelist of lenght zero??
i wanted to use a if loop if($var eq "")
but then i get the error:
Operation "eq": no method found,
left argument in overloaded package XML::LibXML::NodeList,
right argument has no overloaded magic at ./conv line 284.
does anyone knows a solution to my problem?
thx
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
hi all i want to read xml file in perl i am using XML::Simple for this. i am not getting how to read following file
removing xml file due to some reason (1 Reply)
Discussion started by: zedex
1 Replies
2. Shell Programming and Scripting
I am very new to XML. Really I have an excel file that I am trying to read w/ Perl on a Linux machine. I don't have a mod for reading excel files so I have to convert the excel file to xml to be able to read it. I can read the file and everything is ok except...the Number style is being dropped... (0 Replies)
Discussion started by: vincaStar
0 Replies
3. Shell Programming and Scripting
Hello.
Can anybody help me with some sub on perl that can parse config like this:
%CFG (
'databases' => {
'db1' => 'db_11', 'db_12', 'db_13',
'db2' => 'db_21', 'db_22', 'db_23'
}
'datafiles' => {
'datadir1' => 'datadir_11', 'datadir_12',
'datadir2' =>... (4 Replies)
Discussion started by: drack
4 Replies
4. UNIX for Advanced & Expert Users
Hi,
My requirement is like this. I have an XML file which needs to be converted to Tuxedo UD files(param name and param value). Does anybody have a sample perl xml parser script for this? (0 Replies)
Discussion started by: guruprasadpr
0 Replies
5. Shell Programming and Scripting
HI,
I have XML file which is having values as Spanish character (UTF-8 encoding). I am using XML::parser module but my code is not able to read those characters. I did goggling but not able to find suitable solution. Anybody please help me out.
XML file having characters like: ñ
I am... (1 Reply)
Discussion started by: jatanig
1 Replies
6. Shell Programming and Scripting
Q: Where to get a 64 bit Expat.so?
I run a perl script and got this error:
Can't load '/usr/perl5/vendor_perl/5.8.4/i86pc-solaris-64int/auto/XML/Parser/Expat/Expat.so' for module XML:parser::Expat: ld.so.1:myPerl: fatal:... (0 Replies)
Discussion started by: lilili07
0 Replies
7. Programming
Dear Perl Experts,
Could some body help me to find the solution for my problem below:
Input file:
-----------
THE-0 tsjp
THE-32 tsjp
THE-64 tsjp
Output desired:
---------------
THE-0&&-31 tsjp
THE-32&&-63 tsjp
THE-64&&-95 tsjp
Note:
31 = 0+31, (2 Replies)
Discussion started by: askari
2 Replies
8. Shell Programming and Scripting
I want to use sax parser for my application as i have 5 Lakhs of data.
I have the xml file like this
<Nodes>
<Node>
<NodeName>Company</NodeName>
<File>employee_details.csv</File>
<data>employee_data.txt</data>
<Node>
<NodeName>dummy</NodeName>
... (8 Replies)
Discussion started by: vanitham
8 Replies
9. Shell Programming and Scripting
Hello forum, I am having problems to write a bash script.
I am trying to get some information from a web page, I want to format it to XMLTV. This is web page: Programación de las cadenas etb1, etb2, etb3, canal vasco y etb sat | EITB Televisión
I want to get something like this:
<programme... (1 Reply)
Discussion started by: jlazkano
1 Replies
10. Shell Programming and Scripting
The below perl code imports the data in the attached document. However, I can not seem to update the perl code to include a parser like in the desired tab of that document. Thank you :).
Most of the data for the parse is included in the document except for the gene and RNA which can is... (0 Replies)
Discussion started by: cmccabe
0 Replies
LEARN ABOUT MOJAVE
xml::libxml::nodelist
XML::LibXML::NodeList(3) User Contributed Perl Documentation XML::LibXML::NodeList(3)
NAME
XML::LibXML::NodeList - a list of XML document nodes
DESCRIPTION
An XML::LibXML::NodeList object contains an ordered list of nodes, as detailed by the W3C DOM documentation of Node Lists.
SYNOPSIS
my $results = $dom->findnodes('//somepath');
foreach my $context ($results->get_nodelist) {
my $newresults = $context->findnodes('./other/element');
...
}
API
new(@nodes)
You will almost never have to create a new NodeList object, as it is all done for you by XPath.
get_nodelist()
Returns a list of nodes, the contents of the node list, as a perl list.
string_value()
Returns the string-value of the first node in the list. See the XPath specification for what "string-value" means.
to_literal()
Returns the concatenation of all the string-values of all the nodes in the list.
to_literal_delimited($separator)
Returns the concatenation of all the string-values of all the nodes in the list, delimited by the specified separator.
to_literal_list()
Returns all the string-values of all the nodes in the list as a perl list.
get_node($pos)
Returns the node at $pos. The node position in XPath is based at 1, not 0.
size()
Returns the number of nodes in the NodeList.
pop()
Equivalent to perl's pop function.
push(@nodes)
Equivalent to perl's push function.
append($nodelist)
Given a nodelist, appends the list of nodes in $nodelist to the end of the current list.
shift()
Equivalent to perl's shift function.
unshift(@nodes)
Equivalent to perl's unshift function.
prepend($nodelist)
Given a nodelist, prepends the list of nodes in $nodelist to the front of the current list.
map($coderef)
Equivalent to perl's map function.
grep($coderef)
Equivalent to perl's grep function.
sort($coderef)
Equivalent to perl's sort function.
Caveat: Perl's magic $a and $b variables are not available in $coderef. Instead the two terms are passed to the coderef as arguments.
reverse()
Equivalent to perl's reverse function.
foreach($coderef)
Inspired by perl's foreach loop. Executes the coderef on each item in the list. Similar to "map", but instead of returning the list of
values returned by $coderef, returns the original NodeList.
reduce($coderef, $init)
Equivalent to List::Util's reduce function. $init is optional and provides an initial value for the reduction.
Caveat: Perl's magic $a and $b variables are not available in $coderef. Instead the two terms are passed to the coderef as arguments.
perl v5.18.2 2014-02-01 XML::LibXML::NodeList(3)