xml - DOMDocument parsing (php) -


I am parsing an XML file from an API that I have changed in php to a DOMDocument. It's mostly ok, but I have a problem when I do this:

  $ feeditem-> GetElementsByTagName ('additional');  

As part of a normal situation and additional elements are not present in one, which is one of the feeds, I am running in full state then I get an error is.

I tried to do this:

  if (empty ($ feeditem-> getElementsByTagName ('extra')) $ $ extratag = $ feeditem- & Gt; GetElementsByTagName ('additional'); $ Extraname = $ extratag- & gt; Items (0) - & gt; GetAttribute ('name');  

But I get an error

  getAttribute () on a non-object  

Note: When the 'Additional' If the element is contained in every feeddown, the code keeps running. This occurs when there is no one 'extra' element in the feed item that I get the error.

Try to use property of length :

< Pre> $ node = $ feeditem-> GetElementsByTagName ('additional'); If ($ nodes-> Length> 0) {$ extraname = $ extratag-> Items (0) - & gt; GetAttribute ('name'); }

Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -