sma*_*ape 0 perl xpath xml-parsing xml-libxml
在编程方面,我总是遇到一些逻辑问题.我认为这很合乎逻辑,但对我来说很难,因为我无法到达那里.我正在使用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>
Run Code Online (Sandbox Code Playgroud)
我想为除"引用"之外的所有其他RefType选择commentscorrections.我该怎么做.我想通过将所有想要的RefType放在另一个变量中然后使用它来获取其他数据来做到这一点.这是正确的方法,我尝试了一些虚拟变量,如下所示
my $sam = "A" || "B" || "C";
print "test= ";
my $test = <>;
if ($test == $sam) {
print $test;
print "success";} else {
print "NO";}
Run Code Online (Sandbox Code Playgroud)
我知道这对你们中的一些人来说可能是愚蠢的,但是我在一个月左右的时间里写了一个程序而且我有时因为不知道该怎么办而感到沮丧.我尝试学习很多东西.如果这真的是一个愚蠢的问题,请原谅我.
还有,我想过
if(!($foo->findnodes('CommentsCorrectionList/CommentsCorrections[@RefType="Cites"]'))){
do foreach and get the data
}
Run Code Online (Sandbox Code Playgroud)
但在这种情况下,如何避免foreach中的RefType ="Cites"并使其等于我想要的其他RefType.我的意思是我不知道是否可以在foreach语句中使用这样的布尔值.我试图找到并且也做了试验和错误,但手头没什么.任何帮助是极大的赞赏.
谢谢.
CommentsCorrectionList/CommentsCorrections[@RefType != "Cites"]
Run Code Online (Sandbox Code Playgroud)
我个人使用XPath规范作为我的参考,但可能有更友好的参考.
| 归档时间: |
|
| 查看次数: |
196 次 |
| 最近记录: |