Mam komunikację za urządzeniem po api, i motoda komunikacyjna zwraca treść w postaci xmla jako zwrot dla requestu.
Problem w tym że mam mały problem z wyciągnięciem danych.
Zwrot taki wygląda tak:
<?xml version="1.0"?>
<env:Envelope
xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<env:Body>
<getAdminConfigResponse
xmlns="http://www.kostac.com/automation/v1">
<code>100</code>
<message>OK</message>
<adminConfigList>
<adminConfigListEntry>
<slotId>2</slotId>
<dataPort>
<ipAddress>172.28.0.9</ipAddress>
<gatewayAddress>172.28.0.10</gatewayAddress>
<subnetMask>255.255.255.252</subnetMask>
<ipv6AddressAuto>N/A</ipv6AddressAuto>
<enable>1</enable>
<autoNegotiation>1</autoNegotiation>
<linkSpeed>AUTO</linkSpeed>
<currentLinkSpeed>1000</currentLinkSpeed>
<connectorType>optical</connectorType>
<vlanList/>
<icmp>1</icmp>
</dataPort>
<dataPortB>
<ipAddress>172.30.8.1</ipAddress>
<gatewayAddress>172.30.8.2</gatewayAddress>
<subnetMask>255.255.252.0</subnetMask>
<ipv6AddressAuto>N/A</ipv6AddressAuto>
<enable>1</enable>
<autoNegotiation>1</autoNegotiation>
<linkSpeed>AUTO</linkSpeed>
<currentLinkSpeed>1000</currentLinkSpeed>
<connectorType>optical</connectorType>
<vlanList/>
<icmp>0</icmp>
</dataPortB>
</adminConfigListEntry>
</adminConfigList>
</getAdminConfigResponse>
</env:Body>
</env:Envelope>
I teraz chciałem wyciągnąć: "<ipAddress>172.30.8.1</ipAddress>" a dokładniej zawartość tego elementu.
Przygotowałem sobie coś takiego:
$xml_ip_address = '<?xml version="1.0"?>
<env:Envelope
xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<env:Body>
<getAdminConfigResponse
xmlns="http://www.kostac.com/automation/v1">
<code>100</code>
<message>OK</message>
<adminConfigList>
<adminConfigListEntry>
<slotId>2</slotId>
<dataPort>
<ipAddress>172.28.0.9</ipAddress>
<gatewayAddress>172.28.0.10</gatewayAddress>
<subnetMask>255.255.255.252</subnetMask>
<ipv6AddressAuto>N/A</ipv6AddressAuto>
<enable>1</enable>
<autoNegotiation>1</autoNegotiation>
<linkSpeed>AUTO</linkSpeed>
<currentLinkSpeed>1000</currentLinkSpeed>
<connectorType>optical</connectorType>
<vlanList/>
<icmp>1</icmp>
</dataPort>
<dataPortB>
<ipAddress>172.30.8.1</ipAddress>
<gatewayAddress>172.30.8.2</gatewayAddress>
<subnetMask>255.255.252.0</subnetMask>
<ipv6AddressAuto>N/A</ipv6AddressAuto>
<enable>1</enable>
<autoNegotiation>1</autoNegotiation>
<linkSpeed>AUTO</linkSpeed>
<currentLinkSpeed>1000</currentLinkSpeed>
<connectorType>optical</connectorType>
<vlanList/>
<icmp>0</icmp>
</dataPortB>
</adminConfigListEntry>
</adminConfigList>
</getAdminConfigResponse>
</env:Body>
</env:Envelope>
';
$xml = simplexml_load_string($xml_ip_address);
$programme_with_xmlid = $xml->xpath("/env:Envelope/env:Body/getAdminConfigResponse/adminConfigList/adminConfigListEntry/dataPortB/ipAddress");
var_dump($programme_with_xmlid);
Próbowałem różnych xpathów:
/env:Envelope/env:Body/getAdminConfigResponse/adminConfigList/adminConfigListEntry/dataPortB/ipAddress
//dataPortB[1]/ipAddress[1]/text()[1]
I też kilku innych ale nigdy nie udało mi się zwrócić wyników.
Gdy na jakiś generatorach online próbuje wyciągnąć takową wartość to niby te xpathy są podobne do moich ale już w php nie działają.
Czy może ktoś mi uświadomić gdzie jest błąd albo podpowiedzieć coś?
Bo już próbowałem aboslutnej ścieżki jak i relatywnej a i tak nic nie działa.