Skip to content

Commit 5fec5af

Browse files
committed
Fix to use with new XmlUtil.
1 parent 2691921 commit 5fec5af

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/AnyDataset.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use ByJG\AnyDataset\Core\Formatter\XmlFormatter;
77
use ByJG\XmlUtil\File;
88
use ByJG\XmlUtil\XmlDocument;
9+
use ByJG\XmlUtil\XmlNode;
10+
use DOMElement;
911
use InvalidArgumentException;
1012

1113
/**
@@ -121,14 +123,13 @@ private function createFromFile()
121123
$rows = $anyDataSet->selectNodes("row");
122124
foreach ($rows as $row) {
123125
$sr = new Row();
124-
$fields = $row->getElementsByTagName("field");
126+
$fields = XmlNode::instance($row)->selectNodes("field");
127+
/** @var DOMElement $field */
125128
foreach ($fields as $field) {
126-
$attr = $field->attributes->getNamedItem("name");
127-
if (is_null($attr) || is_null($attr->nodeValue)) {
129+
if (!$field->hasAttribute("name")) {
128130
throw new InvalidArgumentException('Malformed anydataset file ' . basename($this->getFilename()));
129131
}
130-
131-
$sr->addField($attr->nodeValue, $field->nodeValue);
132+
$sr->addField($field->getAttribute("name"), $field->nodeValue);
132133
}
133134
$sr->acceptChanges();
134135
$this->collection[] = $sr;
@@ -141,9 +142,8 @@ private function createFromFile()
141142
* Returns the AnyDataset XML representative structure.
142143
*
143144
* @return string XML String
144-
* @throws \ByJG\XmlUtil\Exception\XmlUtilException
145145
*/
146-
public function xml()
146+
public function xml(): string
147147
{
148148
return (new XmlFormatter($this->getIterator()))->toText();
149149
}

0 commit comments

Comments
 (0)