brainite / quipxml
增强的基于SimpleXml的工具包
v0.2.4
2020-08-19 15:28 UTC
Requires
- php: >=5.4
README
QuipXml是一个可连用的PHP对象,用于操作XML。与试图在整个库中复制jQuery语法的其他库不同,Quip试图为SimpleXML提供轻量级扩展,以方便编写更干净的代码,而不在PHP项目中强加JavaScript约定。结果是既快速又易于使用。
基本用法
// The 'load' factory method aligns with SimpleXml constructor arguments. $quip = Quip::load($xml_path, 0, TRUE); $quip = Quip::load($xml_string); // jQuery method names are used where appropriate. $html = $quip->html(); // jQuery method names are adjusted when there is a keyword conflict. $quip->xparent(); // While jQuery syntax is wonderful, you also get PHP advantages: // 1. xpath // 2. access children like properties // 3. use foreach loops $ul = $quip->xpath("//ul")->eq(0); $ul->li->after('<li>New bullet.</li>'); foreach ($quip->xpath("//li")->eq(1) as $li) { } // For advanced operations, just like in jQuery, you can access the DOMNode for a given XML node. $el = $ul->dom();
HHVM对SimpleXML的限制
自2014年3月24日起生效(在travis-ci上确认),您不能在SimpleXml元素上使用魔法自我引用。此代码将无法工作
$sxml = simplexml_load_file('example.xml'); $sxml->original[0] = $expected;
更新:此问题在HHVM 3(在2014年5月30日的travis-ci上确认)中已修复。