I'm using LibXML to retreive some data from an XML file, but I'm having issues getting the XPATH query to work.
I have the following data set:
<gfx> <maintainedButton name="MaintainedPushButton1" > <states> <state stateId="Error" > <caption caption="Error"/> <imageSettings imageName="" /> </state> <state stateId="0" value="0" > <caption caption="AUTO PRESS FOR MANUAL"/> <imageSettings imageName="" /> </state> <state stateId="1" value="1"> <caption caption="MANUAL PRESS FOR AUTO" /> <imageSettings imageName=""/> </state> </states> <animations> <animateVisibility expression="({[MECO9434]ENGINEER_SECURI +TY})
OR (({[MECO9434]OPERATOR_SECURITY}==1) AND ({::[MECO9434]Pro +gram:MECO9432.OFF_A}==1))"/> </animations> <connections> <connection name="Value" expression="{::[MECO9434]Program: +MECO9432.LIC_20_A_M_OIT}"/> <connection name="Indicator" expression="{::[MECO9434]Prog +ram:MECO9432.LIC_20_A_M_OIT}"/> </connections> </maintainedButton> </gfx>
I've sucessfully used the following code to get the button name, but it breaks down when trying to get information about the state.
#!/usr/bin/perl # use strict; use warnings; use threads; use XML::LibXML; my $parser = XML::LibXML->new(); my $doc = $parser->parse_file("file.xml"); foreach my $title ($doc->findnodes('//maintainedButton')) { my $button = $title->findvalue('@name'); $button =~ s/\n/ /; my $state = $title->findvalue('/states/state[@stateId ="0"]/@stateId +'); print "$button\t$state\n"; }
What I'm looking to get is:
MaintainedPushButton1 AUTO PRESS FOR MANUAL
Can someone point out what's wrong with the XPATH query and point me to a good reference so I don't have to keep asking these simple questions?
Thanks,
Shawn Way
In reply to Perl LibXML XPATH query issues. by DunLidjun
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |