php - How to parse SOAP in order to list all Request and Object names -


i'm able parse xml soap when know namespace , request name.

because have different kind of soap requests, request name in soap file . extract of part of soap:

<?xml version="1.0" encoding="utf-8"?> <soap-env:envelope     xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"     xmlns:ns1="http://schema.example.com"     xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xmlns:xsd="http://www.w3.org/2001/xmlschema"    xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/"    soap-env:encodingstyle="http://schemas.xmlsoap.org/soap/encoding/" > <soap-env:body>  **<ns1:sendmailling>**  <campagne xsi:type="ns1:campaign"><activatededup xsi:nil="true"/><billingcode     xsi:nil="true"/><deliveryfax xsi:type="ns1:deliveryfax"/>  <deliverymail xsi:type="ns1:deliverymail">  ... 

php code:

if(is_file($file))     {         $content=file_get_contents($file);           $xml = simplexml_load_string($content);         $xml->registerxpathnamespace('ns1', 'http://schema.example.com');            foreach ($xml->xpath('\\soap-env:') $item)         {             //certainly bad way?             echo "<pre>";                 print_r($item);             echo "</pre>";          }          echo "<pre>";             print_r($xml);         echo "</pre>";       } 

i no result... make appears : 'sendmailling' (identify request name)

when specify

//foreach($xml->xpath('//ns1:sendmailling') $item) 

there no problems.

i tried foreach($xml->xpath('//ns1') $item)
, $xml->xpath('//soap-enc'), $xml->xpath('//body') but...

i had problems understand questions not answer.

if understand right, want select element nodes direct children of <soap-env:body> , in ns1 / http://schema.example.com namespace.

you have registered namespace prefix used simplexmlelement::xpath:

$xml->registerxpathnamespace('ns1', 'http://schema.example.com'); 

you have not yet registered soap-env / http://schemas.xmlsoap.org/soap/envelope/ namespace far can see.

in xpath match element can specify it's namespace. there multiple ways how done:

*               elements in namespace. prefix:*        elements in namespace "prefix" (registered prefix) prefix:local    "local" elements in namespace "prefix" 

for example select elements ns1 prefix:

//ns1:* 

you might want limit because want direct children withn <soap-env:body> register namespace soap-env prefix , extend previous xpath:

/soap-env:body/ns1:* 

this should have elements you're looking for.


(op:) again, when

foreach ($xml->xpath('//soap-env:body/ns1:*') $item) {     echo $item->getname() . "<br>"; } 

all ok request name 'sendmailling'.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -