XML data source - how to access child tags

Hi everyone,


I've got an external XML file that I want to bring into Matrix, and I want to be able to access ALL the tags at ALL levels, and I can't figure out how.



I've set up an XML Data Source asset, popped in the URL, and specified a list of tags that then show up on the details on my data source record set. But I can only access one level of tags. How do I access child tags?



EG XML feed:



<level1tag>something in here</level1tag>

<anotherlevel1>something else here<anotherlevel1>

<thirdlevel1>

<thistag>i need this bit too</thistag>

</thirdlevel1>





I can get level1tag, anotherlevel1 but can't get to thistag.



Surely there must be a way to access all the tags - do I need to look at doing something totally different?



All help very much appreciated!

Thanks,

Charlie.

[quote]
<level1tag>something in here</level1tag>

<anotherlevel1>something else here<anotherlevel1>

<thirdlevel1>

<thistag>i need this bit too</thistag>

</thirdlevel1>





[/quote]



Hi Charlie,

What is the list of tag name you have provided in Matrix for extraction?

Are you using "thistag" as well?



If you use "level1tag", "anotherlevel1", "thirdlevel1" and "thistag" in the Tag Name, you must be extract all the tags from the above example.



Ash

Hi Ash,


Yes, you're right (of course) that does work. My problem is that the XML has a few parent level elements that then all have the same child elements. And one of those repeated child elements is also the same name as a parent element (I didn't design this XML btw!). So when I add in one of those child element names, I end up getting multiple data records created, with different details available on each one, which is going to make it complicated / impossible to get them all back in the right place on my asset list.



However … I have solved my overall problem, by using the JSON method rather than XML, and that allows me to access each of the child elements and place them exactly where I want to on my asset list. So its all looking lovely!



Now I just to figure out a way to print the date for 4 days into the future… but that's another post.



Thanks!

Charlie.

I'm having a similar issue with an XML feed we are consuming.  
Sample XML:

<event>
    <id>5503641540</id>
    <end_date>2013-05-15 14:30:00</end_date>
    <organizer>
        <description />
        <id>122150107</id>
        <long_description>
            It collects, preserves, promotes and provides access to documents that record the lives of Canberra's residents.
        </long_description>
        <url>http://librariesact.eventbrite.com</url>
    </organizer>
    <timezone>Australia/Sydney</timezone>
    <title>T'ai Chi Chuan (Erindale Library)</title>
    <url>http://www.eventbrite.com/event/5503641540/SRCH</url>
</event>
<event>
    ...
    ...
    ...
</event>

 

Using the above code you can see that <id> and <url> are repeated but they sit under different parent elements. When we enter "url" into the Tag Names within Matrix we get multiple records with different data since there are two <url> elements. All we need is the <url> element that is a direct child of the <event> element, and not the one under <organizer>. There are no issues getting <title> or <long_description> as these aren't repeated.

 

Is this a Matrix bug or functioning as normal and a feature request would be in order? We are on 4.10.2 so maybe it has already been resolved?

 

Would something like XSL help in this situation if Matrix cannot access the tags correctly? I've never used it but don't want to waste time going down the wrong path.

 

Charlie - when you say you used the JSON method, do you mean the XML provider had a JSON data source? Or did you convert the XML somehow?

 

Hi Chickensoup64 - I was lucky that the external provider also provided a JSON feed, so I set up a JSON data feed in Matrix to link to that.

 

Would still be good to know if there is a way around this in XML, and if it does need to be a feature request.

 

Thanks, Charlie.

Would something like XSL help in this situation if Matrix cannot access the tags correctly? I've never used it but don't want to waste time going down the wrong path.

 

Yes, you can use XSL to access and output any tags in the given XML document.

 

Chiran

Would still be good to know if there is a way around this in XML, and if it does need to be a feature request.

 

Unfortunately, this is currently not supported, however is a good feature request. The XML data source asset currently gets all the tags with given name under the given root node, regardless of the tree depth. If there are multiple tags with given name, it will just concatenate the value using the specified delimiter.
For example:

 

<lib>
  <book>
    <id>B1</id>
    <name>Africa</name>
    <author>
      <id>A1</id>
    </author>
  </book>
  <book>
    <id>B2</id>
    <name>History</name>
    <author>
      <id>A2</id>
    </author>
  </book>
</lib>
 

For above, if the root node is set to "book" and tags to extract is "id", currently you will get:
record 1: id="B1,A1";
record 2: id="B2,A2";

To address this issue, I think we will need a new option in XML data source asset, enabling which will produce the records like:
record 1: id="B1"; author.id="A1";
record 2: id="B2"; author.id="A2";
 

Chiran

Applying XSLT to the XML feed has worked well - thanks.

 

I've filed a feature request for this at http://bugs.matrix.squiz.net/view_bug.php?bug_id=6243 if anyone is interested.