PHP Xpath:如何从WSDL上的任何方法获取操作URL?

我试图仅使用所需的操作(和wsdl)从任意WSDL中恢复操作URL:

$method = "consultarProcesso";
$wsdl = "https://webserverseguro.tjrj.jus.br/MNI/Servico.svc?wsdl";
$xmlWSDL = new SimpleXMLElement(file_get_contents($wsdl));
$xpath = "//*[local-name()='operation'][@name='$method']";
$result = $xmlWSDL->xpath($xpath);
var_dump($result[0]);

问题是在此示例中,我不知道如何从$ result [0]获取节点值以恢复所需的值:

http://www.cnj.jus.br/servico-intercomunicacao-2.2.2/consultarProcesso

我该怎么做?

fls757126991 回答:PHP Xpath:如何从WSDL上的任何方法获取操作URL?

您可以使用SimpleElement::childrenSimpleElement::attributes的名称空间参数来检索此信息:

// Retrieve the `wsdl:` namespaced children of the operation
[$input,$output] = $result[0]->children('wsdl',true);

// Retrieve the `wsaw:`-namespaced attributes of the input element,// then grab the one named Action
$actionAttribute = $input->attributes('wsaw',true)->Action;

// Convert its value into a string
$actionUrl = (string)$actionAttribute;

(显然,此答案对此已过分评论。)

,

有两种方法可以直接使用input查找感兴趣的xpath元素。您可以按当前的状态使用local-name()

$xpath = "//*[local-name()='operation'][@name='$method']/*[local-name()='input']";

或直接在xpath中指定名称空间:

$xpath = "//wsdl:operation[@name='$method']/wsdl:input";

一旦有了所需的元素,就可以查看Action的命名空间属性:

$result = $xmlWSDL->xpath($xpath)[0];
$namespaces = $result->getNameSpaces();
foreach ($namespaces as $ns) {
    if (isset($result->attributes($ns)['Action'])) $url = (string)$result->attributes($ns)['Action'];
}
echo $url;

输出:

http://www.cnj.jus.br/servico-intercomunicacao-2.2.2/consultarProcesso

Demo on 3v4l.org

本文链接:https://www.f2er.com/3010830.html

大家都在问