Page 1 of 1

Xml query

Posted: Wed Jul 21, 2010 7:18 am
by masama1
I have quite large xml file on different server and i want to make queries from file. Is there any tools to intergrate xml from external source? Anyone interested in to take a look?

Re: Xml query

Posted: Fri Jul 23, 2010 6:38 am
by totophe
You can use XML Made Simple.

It will generate an "SimpleXML" Object (http://php.net/manual/en/book.simplexml.php) that you can use in your templates.

You can access it in smarty via the {$xml} variable.

A good way to start is to do a {$xml|var_dump} to show the variables you can access to.

Re: Xml query

Posted: Fri Jul 23, 2010 11:59 am
by masama1
Sorry i'm not following. i managed to do CD catalog tutorial (http://www.w3schools.com/XML/xml_examples.asp) but if i try to use same logic with my own XML (www.edeamedia.com/testi/testi.xml-> does not work at all.

Compare:
CD Catalog example:
{foreach from=$xml->CD item=CD}
{$CD->ARTIST}
{/foreach}

And my XML:
{foreach from=$xml->item id="439070" itemType="kivihomepagetransfer" item=property name="country_id"}
{$property name="country_id"->value}
{/foreach}

Re: Xml query

Posted: Fri Jul 23, 2010 12:30 pm
by totophe
Play with the following code:

Code: Select all

{foreach from=$xml->item item=element}
  {foreach from=$element->property item=prop}
    <pre>
      {foreach from=$prop->attributes() item=attribute key=name}
        attribute: {$attribute}
        key: {$name}
      {/foreach}

      value: {$prop->value}
    </pre>
  {/foreach}
{/foreach}

Re: Xml query

Posted: Fri Jul 23, 2010 7:19 pm
by masama1
Ok, now i can get whole package. If i want to pick just two values


  Kivinen
  and

  matti.liljaniemi@jatkoaika.com
 

how should i proceed?
foreach loop for every value? ::)