33
44namespace Soap \Encoding \Xml \Reader ;
55
6+ use DOMAttr ;
7+ use DOMNode ;
68use Soap \Encoding \Xml \Node \Element ;
79use Soap \Encoding \Xml \Node \ElementList ;
8- use function VeeWee \Xml \Dom \Locator \Attribute \attributes_list ;
9- use function VeeWee \Xml \Dom \Locator \Element \children as readChildElements ;
10+ use function VeeWee \Xml \Dom \Predicate \is_element ;
1011
1112final class DocumentToLookupArrayReader
1213{
@@ -22,8 +23,13 @@ public function __invoke(Element $xml): array
2223 // Read all child elements.
2324 // The key is the name of the elements
2425 // The value is the raw XML for those element(s)
25- $ elements = readChildElements ($ root );
26- foreach ($ elements as $ element ) {
26+ /** @var iterable<DOMNode> $children */
27+ $ children = $ root ->childNodes ;
28+ foreach ($ children as $ element ) {
29+ if (!is_element ($ element )) {
30+ continue ;
31+ }
32+
2733 $ key = $ element ->localName ?? 'unknown ' ;
2834 $ previousValue = $ nodes [$ key ] ?? null ;
2935 $ currentElement = Element::fromDOMElement ($ element );
@@ -41,13 +47,14 @@ public function __invoke(Element $xml): array
4147
4248 // It might be possible that the child is a regular textNode.
4349 // In that case, we use '_' as the key and the value of the textNode as value.
44- $ content = trim ($ root ->textContent );
45- if (!$ elements ->count () && $ content ) {
50+ if (!$ nodes && $ content = trim ($ root ->textContent )) {
4651 $ nodes ['_ ' ] = $ content ;
4752 }
4853
4954 // All attributes also need to be added as key => value pairs.
50- foreach (attributes_list ($ root ) as $ attribute ) {
55+ /** @var \iterable<DOMAttr> $attributes */
56+ $ attributes = $ root ->attributes ;
57+ foreach ($ attributes as $ attribute ) {
5158 $ key = $ attribute ->localName ?? 'unkown ' ;
5259 $ nodes [$ key ] = $ attribute ->value ;
5360 }
0 commit comments