From f9e705045631ddb774d58e54e1101423e6b395d4 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Sun, 1 Sep 2019 15:30:28 +0300 Subject: Allow loading plist as string For use with "mdls -plist -" et al. --- PropertyList.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/PropertyList.php b/PropertyList.php index c407011..b1d103b 100644 --- a/PropertyList.php +++ b/PropertyList.php @@ -12,12 +12,20 @@ class PropertyList { function __construct($xmlFile) { - if (!file_exists($xmlFile)) { - echo "{$xmlFile}: no such file"; + $loaded = false; + $document = new DOMDocument(); + + if (file_exists($xmlFile)) { + $loaded = $document->load($xmlFile); + } else { + $loaded = $document->loadXML($xmlFile); + } + + if ($loaded === false) { + echo "Failed to load input: {$xmlFile}"; return false; } - $document = new DOMDocument(); - $document->load($xmlFile); + $plistNode = $document->documentElement; $this->root = $plistNode->firstChild; while ($this->root->nodeName == "#text") { -- cgit v1.2.3