Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

How can I force findnodes() to check value of attributes in either xpath1 or xpath2?

by ravi06 (Novice)
on Jul 19, 2013 at 11:16 UTC ( #1045336=perlquestion: print w/replies, xml ) Need Help??

ravi06 has asked for the wisdom of the Perl Monks concerning the following question:

The following piece of code cancatenates the result of both xpaths.
foreach my $node ($xpc->findnodes('/xpath1 | /xpath2')) { foreach my $col(qw/Id Title Book Publisher Platform/) { print $xpc->findvalue($chapter_columns{$col}, $node); } }
I want to first check value of Id in xapth1 and if it is not present, it should look into xpath2.
  • Comment on How can I force findnodes() to check value of attributes in either xpath1 or xpath2?
  • Download Code

Replies are listed 'Best First'.
Re: How can I force findnodes() to check value of attributes in either xpath1 or xpath2?
by Corion (Patriarch) on Jul 19, 2013 at 11:25 UTC

    What Perl code have you written to address this problem?

    Maybe you want to write a Perl program that first checks the attributes for xpath1 and then, if unsuccessful, checks the attributes for xpath2?

    Or maybe you want to combine the two xpath queries into one?

    I recommend modifying xpath1 so it returns all nodes with the appripriate Id attribute. If that is unsuccessful, run the (appropriately modified) xpath2. But that means you will have to learn XPath yourself.

      The Id, Title are in xpath1 an the other elements (Book Publisher Platform) are in xpath2. when the script is run, the out put it produce is "id","Title","","","" "","","Book","Publisher","Platform" whereas I want "id","Title","Book","Publisher","Platform"

        If you want to solve this problem using XPath, I recommend learning XPath.

        If you want to solve this problem using Perl, I recommend you show us the Perl code you have written to address this problem.

        The code you have shown so far does not even contain print statements, so it cannot relate to the problem you are having.

Re: How can I force findnodes() to check value of attributes in either xpath1 or xpath2?
by choroba (Archbishop) on Jul 19, 2013 at 12:02 UTC
    Crossposted at StackOverflow. It is considered polite to inform about crossposting so that people not attending both sites do not waste their time solving a problem already solved at the other end of the wires.
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1045336]
Approved by hdb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2022-05-24 00:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (82 votes). Check out past polls.

    Notices?