Retrieve values/attributes from XML in an array

By: padya

22 Jul 2011

When you google to get a solution to retrieve all the or single tag xml values/attributes you may get approx 10,400,000 results.

Common solution will be to create a module, bring down your own function, bla-bla bla.......

The simplest and statistical way to get is using inbuild drupal functions.

1.  $getXML = drupal_http_request( $url );  //$url is the url to get the xml

2.  To retrieve only single tag.

  • $xmlArray = (int)$this->my_xml_parser( $getXML, "</tag>" );

NB: casting can be of any data type as per needed.  "</tag>" is from which tag to retrieve value.  $getXML is from 1.

                                          OR

2. To retrieve all tags in an array.

  • $xmlArray= simplexml_load_string( $getXML->data );

NB: This will return all the attributes with array. $getXML->data contains all the xml tags.

 

 

No Responses yet to Retrieve values/attributes from XML in an array

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

7 + 10 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

php.png    firefox.png    open_source.png    ubuntu.png    drupal.png    civicrm.png     jquery

About the Author

Recent comments

Follow Me

flickr.png    yahoo.png    facebook.png    twitter.png

google.png    youtube.png    wordpress.png   

       wordpress.png

Ohloh profile for rahulbile

User login