假设有这么一个xml,这个可以不固定
<root>
<home>
<sea id="s1">
<uv name="l1">test.1</op>
<op name="l1">test.2</op>
</sea>
<sea id="s2">
<uv name="l2">test.3</uv>
<op name="l1">test.4</uv>
<uv name="l1">test.5</uv>
</sea>
</home>
<home>...</home>
</root>
我先通过DOMDocument获取到一个ID截点,如下:
$dom = new DOMDocument;
$s1 = $dom->getElementByID('s1');
// 返回一个DOMElement对象..做一些列操作,略
$xpath = new \DOMXpath;
// 获取ID截点下uv的name属性为l1的截点
请问,我如何根据DOMElement对象,快速定位到这个截点,而不是从根目录一级一级往下获取,如:
(new DOMXpath)->query('/root/home/sea/uv[name=l1]');
假设有这么一个xml,这个可以不固定
<root>
<home>
<sea id="s1">
<uv name="l1">test.1</op>
<op name="l1">test.2</op>
</sea>
<sea id="s2">
<uv name="l2">test.3</uv>
<op name="l1">test.4</uv>
<uv name="l1">test.5</uv>
</sea>
</home>
<home>...</home>
</root>
我先通过DOMDocument获取到一个ID截点,如下:
$dom = new DOMDocument;
$s1 = $dom->getElementByID('s1');
// 返回一个DOMElement对象..做一些列操作,略
$xpath = new \DOMXpath;
// 获取ID截点下uv的name属性为l1的截点
请问,我如何根据DOMElement对象,快速定位到这个截点,而不是从根目录一级一级往下获取,如:
(new DOMXpath)->query('/root/home/sea/uv[name=l1]');
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号