Skip to content

Commit

Permalink
Fix loadXml result checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
EreMaijala committed Oct 5, 2023
1 parent 34821e7 commit 56a6251
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/RecordManager/Base/Command/Records/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,11 @@ function ($record) use (
}
$xml = $metadataRecord->toXML();
if ($xpath || (($injectId || $injectIdPrefixed) && !$record['deleted'])) {
$dom = $this->metadataUtils->loadXML($xml);
if (!$dom) {
$errors = '';
$dom = $this->metadataUtils->loadXML($xml, null, 0, $errors);
if (false === $dom) {
throw new \Exception(
"Failed to parse record '{$record['_id']}'"
"Failed to parse record '{$record['_id']}': $errors"
);
}
if ($xpath) {
Expand Down
4 changes: 2 additions & 2 deletions src/RecordManager/Base/Controller/CreatePreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function launch($metadata, $format, $source)

if ('marc' !== $format && substr(trim($metadata), 0, 1) === '<') {
$doc = new \DOMDocument();
if ($this->metadataUtils->loadXML($metadata, $doc)) {
if (false !== $this->metadataUtils->loadXML($metadata, $doc)) {
$root = $doc->childNodes->item(0);
if (in_array($root->nodeName, ['records', 'collection'])) {
// This is a collection of records, get the first one
Expand Down Expand Up @@ -243,7 +243,7 @@ public function getDataSources($format = '')
protected function oaipmhTransform($metadata, $transformations)
{
$doc = new \DOMDocument();
if (!$this->metadataUtils->loadXML($metadata, $doc)) {
if (false === $this->metadataUtils->loadXML($metadata, $doc)) {
throw new \Exception(
'Could not parse XML record'
);
Expand Down

0 comments on commit 56a6251

Please sign in to comment.