@@ -158,6 +158,8 @@ public static function fromFile($fileName)
158
158
}
159
159
160
160
/**
161
+ * Returns the first node (element or attribute) with the given field name and namespace.
162
+ *
161
163
* @param $field
162
164
* @param $ns
163
165
* @param bool $checkAttributes
@@ -166,14 +168,15 @@ public static function fromFile($fileName)
166
168
*/
167
169
private function getNode ($ field , $ ns , $ checkAttributes = true )
168
170
{
169
- $ rdfDesc = $ this ->getRDFDescription ($ ns );
170
-
171
171
// check for field as an element or an attribute
172
172
$ query = ($ checkAttributes )? $ field . '|@ ' . $ field : $ field ;
173
- $ result = $ this ->xpath ->query ($ query , $ rdfDesc );
174
173
175
- if ($ result ->length ) {
176
- return $ result ->item (0 );
174
+ $ rdfDescriptions = $ this ->getRDFDescriptions ($ ns );
175
+ foreach ($ rdfDescriptions as $ rdfDesc ) {
176
+ $ result = $ this ->xpath ->query ($ query , $ rdfDesc );
177
+ if ($ result ->length ) {
178
+ return $ result ->item (0 );
179
+ }
177
180
}
178
181
179
182
return null ;
@@ -267,29 +270,28 @@ private function getSeq($field, $namespace)
267
270
268
271
return null ;
269
272
}
270
-
271
273
/**
274
+ * Returns all `rdf:Description` elements with the given namespace.
275
+ *
272
276
* @param $namespace
273
277
*
274
- * @return \DOMNode|null
278
+ * @return array Array of \DOMNode
275
279
*/
276
- private function getRDFDescription ($ namespace )
280
+ private function getRDFDescriptions ($ namespace )
277
281
{
278
- // element
279
- $ description = $ this ->xpath ->query ("//rdf:Description[*[namespace-uri()=' $ namespace']] " );
280
-
281
- if ($ description ->length > 0 ) {
282
- return $ description ->item (0 );
283
- }
282
+ $ result = [];
284
283
285
- // attribute
286
- $ description = $ this ->xpath ->query ("//rdf:Description[@*[namespace-uri()=' $ namespace']] " );
284
+ $ element_query = "//rdf:Description[*[namespace-uri()=' $ namespace']] " ;
285
+ $ attribute_query = "//rdf:Description[@*[namespace-uri()=' $ namespace']] " ;
286
+ foreach ([$ element_query , $ attribute_query ] as $ query ) {
287
+ $ description = $ this ->xpath ->query ($ query );
287
288
288
- if ($ description ->length > 0 ) {
289
- return $ description ->item (0 );
289
+ if ($ description ->length > 0 ) {
290
+ $ result = array_merge ($ result , iterator_to_array ($ description ));
291
+ }
290
292
}
291
293
292
- return null ;
294
+ return $ result ;
293
295
}
294
296
295
297
/**
0 commit comments