Add basic XML parser

This commit is contained in:
Steffen Lange 2023-09-09 23:52:09 +02:00
parent e0a07c74d0
commit a46749c822

View file

@ -49,6 +49,18 @@ abstract class PatchBase {
} }
return false; 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 { protected function fetch_yaml(string $url, array $opts = array()) : bool {
$str = $this->curl($url, $opts); $str = $this->curl($url, $opts);
if ($str) { if ($str) {
@ -86,6 +98,13 @@ abstract class PatchBase {
} }
return false; 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 { protected function parse_yaml(string $key, string $re = '/(.*)/') : bool {
return $this->parse_json($key, $re); return $this->parse_json($key, $re);
} }