XML MadeSimple [Default template] [Solved]
XML MadeSimple [Default template] [Solved]
Hello,
Could you please provide an example for the default template required to retrieve and display a XML data feed within CMSMS.
My XMl data is of the format;
Thank you in advance for any assistance,
Could you please provide an example for the default template required to retrieve and display a XML data feed within CMSMS.
My XMl data is of the format;
Thank you in advance for any assistance,
Last edited by jo8e on Mon Mar 15, 2010 9:05 am, edited 1 time in total.
Re: XML MadeSimple [Default template]
Dear Jo8e,
The best way to create templates with XML Made Simple is to explore step by step the process.
What you can first do is : {$xml|print_r} who'll output the full xml structure.
For example, let's take the url http://www.w3schools.com/XML/simple.xml and make a feed in XMLMS.
1. We do a {$xml|print_r} and we see that:
We see that there is multiple "food" elements.
2. We do a foreach on food and we output the name:
It will give us:
3. You can now play with that with your own feeds 
The best way to create templates with XML Made Simple is to explore step by step the process.
What you can first do is : {$xml|print_r} who'll output the full xml structure.
For example, let's take the url http://www.w3schools.com/XML/simple.xml and make a feed in XMLMS.
1. We do a {$xml|print_r} and we see that:
Code: Select all
SimpleXMLElement Object
(
[food] => Array
(
[0] => SimpleXMLElement Object
(
[name] => Belgian Waffles
[price] => $5.95
[description] => two of our famous Belgian Waffles with plenty of real maple syrup
[calories] => 650
)
[1] => SimpleXMLElement Object
(
[name] => Strawberry Belgian Waffles
[price] => $7.95
[description] => light Belgian waffles covered with strawberries and whipped cream
[calories] => 900
)
[2] => SimpleXMLElement Object
(
[name] => Berry-Berry Belgian Waffles
[price] => $8.95
[description] => light Belgian waffles covered with an assortment of fresh berries and whipped cream
[calories] => 900
)
[3] => SimpleXMLElement Object
(
[name] => French Toast
[price] => $4.50
[description] => thick slices made from our homemade sourdough bread
[calories] => 600
)
[4] => SimpleXMLElement Object
(
[name] => Homestyle Breakfast
[price] => $6.95
[description] => two eggs, bacon or sausage, toast, and our ever-popular hash browns
[calories] => 950
)
)
)
2. We do a foreach on food and we output the name:
Code: Select all
{foreach from=$xml->food item=food}
<p>{$food->name}</p>
{/foreach}
Code: Select all
<p>Belgian Waffles</p>
<p>Strawberry Belgian Waffles</p>
<p>Berry-Berry Belgian Waffles</p>
<p>French Toast</p>
<p>Homestyle Breakfast</p>

Re: XML MadeSimple [Default template]
Hi ..and excuse me for jumping into this post..
I was fighting with this XML schema in XMLMS a while ago but gave it up due to other projects (module tests)
Any idea?
JanB
I was fighting with this XML schema in XMLMS a while ago but gave it up due to other projects (module tests)
Any idea?
Code: Select all
<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
xmlns:rs='urn:schemas-microsoft-com:rowset'
xmlns:z='#RowsetSchema'>
<s:Schema id='RowsetSchema'>
<s:ElementType name='row' content='eltOnly' rs:updatable='true'>
<s:AttributeType name='MemberId' rs:number='1' rs:maydefer='true' rs:writeunknown='true' rs:basetable='tblMember'
rs:basecolumn='MemberId' rs:keycolumn='true' rs:autoincrement='true'>
<s:datatype dt:type='int' dt:maxLength='4' rs:precision='10' rs:fixedlength='true'/>
</s:AttributeType>
<s:AttributeType name='Lastname' rs:number='2' rs:nullable='true' rs:maydefer='true' rs:writeunknown='true'
rs:basetable='tblMember' rs:basecolumn='Lastname'>
<s:datatype dt:type='string' dt:maxLength='25'/>
</s:AttributeType>
<s:AttributeType name='Firstname' rs:number='3' rs:nullable='true' rs:maydefer='true' rs:writeunknown='true'
rs:basetable='tblMember' rs:basecolumn='Firstname'>
<s:datatype dt:type='string' dt:maxLength='15'/>
</s:AttributeType>
<s:extends type='rs:rowbase'/>
</s:ElementType>
</s:Schema>
<rs:data>
<z:row MemberId='1' Lastname='Lastname' Firstname='Firstname'/>
</rs:data>
</xml>
Re: XML MadeSimple [Default template]
Thank you for the example. I have been able to successfully get your example working on my site but I am unable to get any of the xml data from my feed to display.
The xml data source is slightly different, any help would be appreciated.
http://www.testurl
http://testurl/15286.jpg
test site
2010-03-15T12:16:24
I am trying to get the Listing info to display and have tried the following but does not seem to work,
{foreach from=$xml->Listings item=Listings}
{$Listing->Title}
{/foreach}
The xml data source is slightly different, any help would be appreciated.
http://www.testurl
http://testurl/15286.jpg
test site
2010-03-15T12:16:24
I am trying to get the Listing info to display and have tried the following but does not seem to work,
{foreach from=$xml->Listings item=Listings}
{$Listing->Title}
{/foreach}
Re: XML MadeSimple [Default template]
{foreach from=$xml->Listings->Listing item="Listings"}
{$Listings->Title}
{/foreach}
JanB
{$Listings->Title}
{/foreach}
JanB
Re: XML MadeSimple [Default template]
Could you try this ?
Or else to post here the result of this:
Code: Select all
{foreach from=$xml->Listings item="Listings"}
{$Listings->Title}<br />
{/foreach}
Code: Select all
{foreach from=$xml->Listings item="Listings"}
{$Listings|var_dump}<br />
{/foreach}
Re: XML MadeSimple [Default template]
totophe ??
won't work..
works!
It is easier to understand looking at the output from {$xml|@print_r}
(hint: look at the page source)
JanB
Code: Select all
{foreach from=$xml->Listings item="Listings"}
{$Listings->Title}<br />
{/foreach}
Code: Select all
{foreach from=$xml->Listings->Listing item="Listings"}
{$Listings->Title}<br />
{/foreach}
It is easier to understand looking at the output from {$xml|@print_r}
(hint: look at the page source)
Code: Select all
SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 1234
[nickname] => test
[version] => 1.0.0
[updateUrl] => http://www.testurl/
)
[Listings] => SimpleXMLElement Object
(
[@attributes] => Array
(
[generated] => 2010-03-14T12:14:27
[expires] => 2010-03-14T12:19:27
)
[Listing] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 1234567
)
[Url] => http://www.testurl
[PhotoUrl] => http://testurl/15286.jpg
[Title] => test site
[EndDate] => 2010-03-15T12:16:24
)
)
)
Re: XML MadeSimple [Default template]
Janb, yeah, I probably was tired when I made my reply 
Neverthenless, the second one is not logic. Listings should be a list of items.
Otherwise, it make no sense...

Neverthenless, the second one is not logic. Listings should be a list of items.
Code: Select all
{foreach from=$xml->Listings item=listing}
A listing object
{/foreach}
Re: XML MadeSimple [Default template]
JanB, for your other question, what does the var_dump gives you ?
Re: XML MadeSimple [Default template]
Hi totophe
I'm not sure what the purpose of his xml document is, but if there have been more than one element at the same level, the code is correct.
If there is only one element, the loop is not necessary and could be like this:
If we don't know how many attributes there is in a certain element we can write it like this:
JanB
jo8e gives us an xml with only one element at the Listing level.Neverthenless, the second one is not logic. Listings should be a list of items.
I'm not sure what the purpose of his xml document is, but if there have been more than one element at the same level, the code is correct.
If there is only one element, the loop is not necessary and could be like this:
Code: Select all
{$xml->Listings->Listing->Title}
Code: Select all
{foreach from=$xml->Listings->Listing key=KeySub item="ItemSub"}
{foreach from=$ItemSub key=KeySubs item=ItemSubs}
{if $KeySubs}{$KeySubs}:{/if} {$ItemSubs}<br />
{/foreach}
{/foreach}
Should give us all elements and attributes / values in "Listings"...JanB, for your other question, what does the var_dump gives you ?
Code: Select all
object(SimpleXMLElement)#151 (2) { ["@attributes"]=> array(2) { ["generated"]=> string(19) "2010-03-14T12:14:27" ["expires"]=> string(19) "2010-03-14T12:19:27" } ["Listing"]=> object(SimpleXMLElement)#152 (5) { ["@attributes"]=> array(1) { ["id"]=> string(7) "1234567" } ["Url"]=> string(18) "http://www.testurl" ["PhotoUrl"]=> string(24) "http://testurl/15286.jpg" ["Title"]=> string(9) "test site" ["EndDate"]=> string(19) "2010-03-15T12:16:24" } }
JanB
Last edited by janb on Mon Mar 15, 2010 6:19 am, edited 1 time in total.
Re: XML MadeSimple [Default template]

Re: XML MadeSimple [Default template]
Glad to help jo8e 
Don't forget to add [Solved] to the subject..
JanB

Don't forget to add [Solved] to the subject..
JanB
Re: XML MadeSimple [Default template]
And does it ? I didn't had time/opportunity to check that actually. As I return the SimpleXMLElement, if SimpleXML support it, you should have it.janb wrote:Should give us all elements and attributes / values in "Listings"...JanB, for your other question, what does the var_dump gives you ?
Code: Select all
object(SimpleXMLElement)#151 (2) { ["@attributes"]=> array(2) { ["generated"]=> string(19) "2010-03-14T12:14:27" ["expires"]=> string(19) "2010-03-14T12:19:27" } ["Listing"]=> object(SimpleXMLElement)#152 (5) { ["@attributes"]=> array(1) { ["id"]=> string(7) "1234567" } ["Url"]=> string(18) "http://www.testurl" ["PhotoUrl"]=> string(24) "http://testurl/15286.jpg" ["Title"]=> string(9) "test site" ["EndDate"]=> string(19) "2010-03-15T12:16:24" } }
JanB
Best regards,
Totophe
Re: XML MadeSimple [Default template] [Solved]
It does ...If you had time to look at the answer 

JanBShould give us all elements and attributes / values in "Listings"...
Code:
object(SimpleXMLElement)#151 (2) { ["@attributes"]=> array(2) { ["generated"]=> string(19) "2010-03-14T12:14:27" ["expires"]=> string(19) "2010-03-14T12:19:27" } ["Listing"]=> object(SimpleXMLElement)#152 (5) { ["@attributes"]=> array(1) { ["id"]=> string(7) "1234567" } ["Url"]=> string(18) "http://www.testurl" ["PhotoUrl"]=> string(24) "http://testurl/15286.jpg" ["Title"]=> string(9) "test site" ["EndDate"]=> string(19) "2010-03-15T12:16:24" } }
Re: XML MadeSimple [Default template] [Solved]
Hi :),
I am using the XML Made Simple module too.
I haven't any problem to display items, but I'd like to display only the latest 3. I used the parameter "max_items" into the tag but it doesn't work.
Do you have an idea of how to do ?
Thanks
Cécile
I am using the XML Made Simple module too.
I haven't any problem to display items, but I'd like to display only the latest 3. I used the parameter "max_items" into the tag but it doesn't work.
Do you have an idea of how to do ?
Thanks
Cécile
Last edited by oaouh on Thu Apr 15, 2010 9:13 am, edited 1 time in total.