66use ByJG \AnyDataset \Core \Formatter \XmlFormatter ;
77use ByJG \XmlUtil \File ;
88use ByJG \XmlUtil \XmlDocument ;
9+ use ByJG \XmlUtil \XmlNode ;
10+ use DOMElement ;
911use 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