From a46749c82213dd9ba4a124e62ed55bcb37ea3b4f Mon Sep 17 00:00:00 2001 From: Steffen Lange Date: Sat, 9 Sep 2023 23:52:09 +0200 Subject: [PATCH] Add basic XML parser --- PatchBase.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/PatchBase.php b/PatchBase.php index d42d57a..5445eed 100644 --- a/PatchBase.php +++ b/PatchBase.php @@ -49,6 +49,18 @@ abstract class PatchBase { } return false; } + protected function fetch_xml(string $url, array $opts = array()) : bool { + $str = $this->curl($url, $opts); + if ($str) { + if (!($this->data = simplexml_load_string($str))) + return false; + $ns = $this->data->getDocNamespaces(true); + foreach ($ns as $n => $u) + $this->data->registerXPathNamespace($n, $u); + return true; + } + return false; + } protected function fetch_yaml(string $url, array $opts = array()) : bool { $str = $this->curl($url, $opts); if ($str) { @@ -86,6 +98,13 @@ abstract class PatchBase { } return false; } + protected function parse_xml(string $key, string $re = '/(.*)/') : bool { + if ($res = $this->data->xpath($key)) { + $this->data = (string)$res[0]; + return $this->parse($re); + } + return false; + } protected function parse_yaml(string $key, string $re = '/(.*)/') : bool { return $this->parse_json($key, $re); }