开发者

How to use a RegEx in Perl's LibXML findnodes

I have the following in an XML Document:

<ul class="toggle-control toggle-retain-state">

I'm using XML::LibXML to parse the entire document, and I need to take action when it finds the above item. The code I have inherited was:

my ($toggle_container) = $xRoot->findnodes('.//*[@id = "toggle-control"]');

It seems that the first problem with that code is that the attribute is class, not id. So I changed that to class, but it still fails to find it. I'm guessing it is because of the class being "toggle-control toggle-retain-state", but What I'm really looking for is a match anytime it sees just the toggle-control in the class attribute. How do I change the findnodes call开发者_高级运维 to make that happen?


Use:

//ul[contains(concat(' ', @class, ' '), ' toggle-control ')]

Remark: Always try to avoid the // abbreviation when the structure of the XML document is known. Using the // abbreviation may lead to significant inefficiency.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜