0

在编程方面,我总是陷入一些逻辑问题。我认为这是合乎逻辑且容易的,但对我来说很难,因为我无法到达那里。我正在使用 XML::LibXML 来解析 XML 文件。现在在下面的代码中

<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>

我想为除“引用”之外的所有其他 RefType 选择评论更正。我该怎么做。我想通过将所有想要的 RefTypes 放在另一个变量中,然后使用它来获取其他数据来做到这一点。这是正确的方法吗,我尝试了一些虚拟变量,如下所示

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

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

我知道这对你们中的一些人来说可能很愚蠢,但是我在一个月左右的时间里编写了一个程序,有时我会因为不知道该怎么做而感到沮丧。我尝试学习很多东西。如果这真的是一个愚蠢的问题,请原谅我。

另外,我想这样做

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

但在这种情况下,我如何避免 foreach 中的 RefType="Cites" 并使其等于我想要的另一个 RefType。我的意思是我不知道这种布尔值是否可以在 foreach 语句中使用。我试着寻找,也做了试验和错误,但手头没有。任何帮助是极大的赞赏。

谢谢你。

4

1 回答 1

7
CommentsCorrectionList/CommentsCorrections[@RefType != "Cites"]

我个人使用XPath 规范作为我的参考,但那里可能有更友好的参考。

于 2011-10-04T06:11:15.870 回答