XML::LibXML parsing and choosing element a quick one

224 views Asked by At

I always get stuck at some logic questions when it comes to programming. This is logical and easy, I think, but hard for me, as I am unable to get there. I am using XML::LibXML to parse XML files. Now in the following code

<CommentsCorrectionsList>
<CommentsCorrections RefType="Cites">
<RefSource>Brain Cogn. 2005 Jul;58(2):245</RefSource>
</CommentsCorrections>
<CommentsCorrections RefType="RepublishedIn">
<RefSource>Brain Cogn. 2005 Jul;58(2):246-8</RefSource>
<PMID Version="1">16044513</PMID>
</CommentsCorrections>
<CommentsCorrections RefType="PartialRetractionOf">
<RefSource>Curr Opin Organ Transplant. 2001 Mar;6(1):95-101</RefSource>
</CommentsCorrections>
</CommentsCorrectionsList>

I want to choose commentscorrections for all other RefType except for 'Cites'. How do I do it. I thought of doing it by putting all the wanted RefTypes in another variable and then using it to get the other data. Is it the right way, I tried with some dummy variables like the following

my $sam = "A" || "B" || "C";

print "test= ";
my $test = <>;
if ($test == $sam) {
print $test;
print "success";} else {
print "NO";}

I know this may be silly for some of you but I writing a program since a month or so and I sometime get frustrated because I don't know what to do. I try to learn many things. Please forgive me if this is really a silly question.

Also, I thought to do

if(!($foo->findnodes('CommentsCorrectionList/CommentsCorrections[@RefType="Cites"]'))){
do foreach and get the data
}

But in this case how do I avoid the RefType="Cites" in foreach and make it equal to the other RefType which I want. I mean I don't know if such boolean can be used in foreach statement. I tried finding and also did trial and error but nothing in hand. Any help is greatly appreciated.

Thank you.

1

There are 1 answers

1
ikegami On BEST ANSWER
CommentsCorrectionList/CommentsCorrections[@RefType != "Cites"]

I personally use the XPath spec as my reference, but there might be friendlier references out there.