xpath dla xml brak poprawnego zwrotu |
xpath dla xml brak poprawnego zwrotu |
24.09.2022, 14:25:09
Post
#1
|
|
Grupa: Zarejestrowani Postów: 11 Pomógł: 0 Dołączył: 21.08.2010 Ostrzeżenie: (0%) |
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:
I teraz chciałem wyciągnąć: "<ipAddress>172.30.8.1</ipAddress>" a dokładniej zawartość tego elementu. Przygotowałem sobie coś takiego:
Próbowałem różnych xpathów:
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. |
|
|
24.09.2022, 14:58:30
Post
#2
|
|
Grupa: Zarejestrowani Postów: 324 Pomógł: 105 Dołączył: 7.08.2012 Ostrzeżenie: (0%) |
To wygląda na problem z namespace.
Sprawdź 1. i 2. komentarz: https://www.php.net/manual/en/simplexmlelement.xpath.php A samo zapytanie xpath można skrócić do "//ipAddress". |
|
|
24.09.2022, 15:33:37
Post
#3
|
|
Grupa: Zarejestrowani Postów: 11 Pomógł: 0 Dołączył: 21.08.2010 Ostrzeżenie: (0%) |
Ok komentarz z dokumentacji pomógł, problem rzeczywiście z namespace.
Kolejnym problemem że maszyna która jest u klienta ma stary system i starego php i musi tam być jakiś bug. Nawet po str_replace na wersji 5.5.9 tego xpath nie działa. Dopiero od 5.5.30 w górę jest zwracany wynik. Ale to już problem samego php, a za pomoc dzięki. |
|
|
24.09.2022, 18:46:10
Post
#4
|
|
Grupa: Zarejestrowani Postów: 6 782 Pomógł: 1826 Dołączył: 11.03.2014 Ostrzeżenie: (0%) |
-------------------- |
|
|
Wersja Lo-Fi | Aktualny czas: 21.09.2024 - 20:22 |