DOMXPath无法使用有效表达式

问题描述 投票:0回答:1

我有以下SVG:

<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 18.1.1, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
     viewBox="-194.2 -103.1 178.2 480.9" enable-background="new -194.2 -103.1 178.2 480.9" xml:space="preserve">
<filter  height="140%" width="140%" id="Filter_1" y="-20%" x="-20%" color-interpolation-filters="sRGB">
    <feColorMatrix  type="matrix" result="result1" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0" in="SourceGraphic">
        </feColorMatrix>
</filter>
<g id="color1">
    <g transform="matrix( 1, 0, 0, 1, -0.3,27) ">
        <g id="Layer_1_1_">
            <g transform="matrix( 1, 0, 0, 1, 0,0) ">
                <g>
                    <g>
                        <path fill="#999999" d="..."/>
                    </g>
                </g>
            </g>
        </g>
    </g>
</g>
<g id="color2">
    <g transform="matrix( 1, 0, 0, 1, -0.4,18.65) ">
        <g id="Layer_1_2_">
            <g transform="matrix( 1, 0, 0, 1, 0,0) ">
                <g>
                    <g>
                        <path fill="#666666" d="..."/>
                    </g>
                </g>
            </g>
        </g>
    </g>
</g>
<g id="lineart_1_">
    <g transform="matrix( 1, 0, 0, 1, -0.3,27) ">
        <g id="Layer_2">
            <g transform="matrix( 1, 0, 0, 1, 0,0) ">
                <g>
                    <path fill="none" stroke="#000000" stroke-width="0.5" stroke-linecap="round" stroke-linejoin="round" d="..."/>
                </g>
            </g>
        </g>
        <g id="lineart">
            <g transform="matrix( 1, 0, 0, 1, 0,0) ">
                <g>
                    <g>
                        <path d="..."/>
                    </g>
                </g>
            </g>
        </g>
    </g>
</g>
<g id="itemMask">
    <g transform="matrix( 1, 0, 0, 1, -0.3,27) ">
        <g id="Layer_1_3_">
            <g transform="matrix( 1, 0, 0, 1, 0,0) ">
                <g filter="url(#Filter_1)">
                    <g>
                        <path fill="#999999" d="..."/>
                    </g>
                </g>
            </g>
        </g>
    </g>
</g>
<g id="actions">
</g>
</svg>

我已经制作了以下PHP代码来提取具有不匹配或部分匹配线稿的ID的第一级元素。

<?php
$thisEntryDoc = new DOMDocument();
$thisEntryDoc->load('test.svg');
$xpath = new DOMXpath($thisEntryDoc);
$xpath->registerNamespace('svg', "http://www.w3.org/1999/xlink");
$elements = $xpath->query("//svg:svg/svg:g[not(contains(@id, 'lineart'))]");
foreach($elements as $element) {
    echo "Found {$element->nodeName}\n";
}
?>

这没什么。我已经使用在线工具测试了XPath,它运行正常。产生任何结果的唯一表达是//*

我完全不知所措。有没有人知道为什么验证的XPath表达式根本不起作用?

php svg domxpath
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.