<p>It appears now that this is an issue with the plugin being unable to read attributes of a node which has sub-nodes. The developer has noted this, and will hopefully post a fix. In the meantime as work around I used a short php script on the server to call the XML file first and rework the data into a format that the plugin can read.</p>

CC BY-SA 3.0
2016-06-19T00:43:16.757Z
2016-06-19T00:43:16.757Z
Jack McKenzie
<p>I'm trying to extract an attribute from a top level XML node but having some difficulty.</p>

<p>Given some XML:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;slots&gt;
  &lt;slot start="Monday" finish="Tuesday"&gt;
    &lt;title id="1234"&gt;John&lt;/title&gt;
  &lt;/slot&gt;
  &lt;slot start="Thursday" finish="Friday"&gt;
    &lt;title id="5678"&gt;Fred&lt;/title&gt;
  &lt;/slot&gt;
&lt;/slots&gt; 
</code></pre>

<p>and some Twig:</p>

<pre><code>{% set params = {
        url: 'http://above.xml',
        type: 'xml',
} %}
{% set feed = craft.feedme.feed(params) %}
</code></pre>

<p>I can extract values and attributes from the inner nodes</p>

<pre><code>{{feed.slots.slot.0.title.attributes.id}}
{{feed.slots.slot.0.title}}
</code></pre>

<p>which yields <code>1234 John</code> as I would expect. But now, how do I get the attributes from the slot node e.g. I want the 'Monday'. I've tried something like</p>

<pre><code>{{feed.slots.slot.0.attributes.start}}
</code></pre>

<p>but that just throws an error.</p>

<p><strong>EDIT:</strong> If I change the XML (remove the inner title nodes) to</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;slots&gt;
  &lt;slot start="Monday" finish="Tuesday"&gt;
  &lt;/slot&gt;
  &lt;slot start="Thursday" finish="Friday"&gt;
  &lt;/slot&gt;
&lt;/slots&gt; 
</code></pre>

<p>then </p>

<pre><code>{{feed.slots.slot.0.attributes.start}}
</code></pre>

<p>works. So maybe the question now is how do I extract attributes from a node that has sub-nodes?</p>

CC BY-SA 3.0
2016-05-18T05:12:12.010Z
By using the dump command it seems to me that if a node has sub nodes, its attributes are not loaded into the array (craft.feedme.feed(params)).
Jack McKenzie
<plugin-feedme>
Extracting an attribute from top level node of a Feedme XML feed using template
# Extracting an attribute from top level node of a Feedme XML feed using template

(Asked by: username_0 on 2016-05-18)

I'm trying to extract an attribute from a top level XML node but having some difficulty.
Given some XML:


  
    John
  
  
    Fred
  
 

and some Twig:
{% set params = {
        url: 'http://above.xml',
        type: 'xml',
} %}
{% set feed = craft.feedme.feed(params) %}

I can extract values and attributes from the inner nodes
{{feed.slots.slot.0.title.attributes.id}}
{{feed.slots.slot.0.title}}

which yields 1234 John as I would expect. But now, how do I get the attributes from the slot node e.g. I want the 'Monday'. I've tried something like
{{feed.slots.slot.0.attributes.start}}

but that just throws an error.
EDIT: If I change the XML (remove the inner title nodes) to


  
  
  
  
 

then 
{{feed.slots.slot.0.attributes.start}}

works. So maybe the question now is how do I extract attributes from a node that has sub-nodes?

**Tags:** plugin-feedme
> **Comments:**
> **username_0**: By using the dump command it seems to me that if a node has sub nodes, its attributes are not loaded into the array (craft.feedme.feed(params)).  

---

## 1 answers

### Answer by username_0 on 2016-06-19. Score: 1 | Accepted answer

It appears now that this is an issue with the plugin being unable to read attributes of a node which has sub-nodes. The developer has noted this, and will hopefully post a fix. In the meantime as work around I used a short php script on the server to call the XML file first and rework the data into a format that the plugin can read.


---

