0

好的,所以我有这个 xml:

<resin xmlns="http://caucho.com/ns/resin" xmlns:resin="urn:java:com.caucho.resin">
<cluster>
<host host-name="www.1.com">
<host-alias>1.com</host-alias>
<root-directory>c:/docroot</root-directory>
<web-app id="/" document-directory="."/>
</host>
<host host-name="www.2.com">
<host-alias>2.com</host-alias>
<root-directory>c:/docroot</root-directory>
<web-app id="/" document-directory="."/>
</host>
</cluster>
</resin>

如果我使用它,我如何获取(在 php 中)主机名“www.1.com”的 xpath:

$items = $xpath->query(sprintf('//host[@host-name="%s"]', $hostNameToLookFor));

没有

xmlns="http://caucho.com/ns/resin" xmlns:resin="urn:java:com.caucho.resin"

有用

请帮忙,它让我发疯!谢谢!

4

1 回答 1

0
        $data = <<<xml
<resin xmlns="http://caucho.com/ns/resin" xmlns:resin="urn:java:com.caucho.resin">
<cluster>
<host host-name="www.1.com">
<host-alias>1.com</host-alias>
<root-directory>c:/docroot</root-directory>
<web-app id="/" document-directory="."/>
</host>
<host host-name="www.2.com">
<host-alias>2.com</host-alias>
<root-directory>c:/docroot</root-directory>
<web-app id="/" document-directory="."/>
</host>
</cluster>
</resin>

xml;

        $xml = new SimpleXMLElement($data);
        $xml->registerXPathNamespace('ns', 'http://caucho.com/ns/resin');
        $xml->registerXPathNamespace('resin', 'urn:java:com.caucho.resin');

        foreach ($xml->xpath ('//ns:host[@host-name="www.2.com"]') as $v)
        {
            // ...
        }
于 2012-09-13T13:12:18.077 回答