We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

XML Parser Class Usage

Development and Programming

Andrew Armitage's avatar
Andrew Armitage
86 posts
13 years ago
Andrew Armitage's avatar Andrew Armitage

I’m wanting to parse XML data with the EE XML parser class and came across this post. I can get the values I need out of the XML, but what if I don’t know the precise structure of the XML?

Calling a child value by number is returning different results as the XML structure changes. Ideally I’d like to be able to call like this (based on the docs example here):

$xml_obj->emails->email->subject

Is this possible? Anyone know how to do it?

Thanks.

       
Andrew Armitage's avatar
Andrew Armitage
86 posts
13 years ago
Andrew Armitage's avatar Andrew Armitage

I’ve tried a few alternatives here and so far come up with the following which allows me to target a specific tag, regardless of where abouts in the XML the tag is.

Can anyone comment on whether this is a sensible approach? Seems a little unwieldy to me…

$this->EE->load->library('xmlparser');
$xml_obj = $this->EE->xmlparser->parse_xml($result);

foreach($xml_obj->children as $key => $event)
{
     foreach($event->children as $ckey => $item)
     {
          if($item->tag == "Start") 
          {
               echo $item->value.'<br>';      
          }                             
     }
}

Any suggestions will be gratefully received 😊

       
Dan Decker's avatar
Dan Decker
7,338 posts
13 years ago
Dan Decker's avatar Dan Decker

Hi Andrew,

Thanks for posting to the forums!

This falls more in line with Development and Programming, so I’m gonna get it over there so the Community can get you the answers you are looking for.

Cheers!

       
R.K.Foster's avatar
R.K.Foster
138 posts
13 years ago
R.K.Foster's avatar R.K.Foster

Greetings,

I posted another similar thread here: http://ellislab.com/forums/viewthread/230789/

Are you still working on this and did you find a solution?

Thanks, Bob.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.