Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
就像我在标题中所说的那样,我想知道是否有可能以及如何递归地解析 XML 文档并返回所有具有给定参数的节点。
我实际上想要做的是加载和 XHTML 文档并返回所有具有等于先前定义值的类的节点(P 节点、DIV 节点等)。
使用 xpath 查找节点,然后循环:
$xml = new SimpleXMLElement($string); $nodes = $xml->xpath("//*[@class='myclass']"); foreach ($nodes as $node) { // ... }
(实际上没有测试过,但它应该是正确的。)