Jump to content

DOMDocument parsing


greenheart

Recommended Posts

Hello, I am parsing an xml file from an API which I have converted into a DOMDocument in php. This is mostly fine but one problem I have is when I do this:

$feeditem->getElementsByTagName('extra');

 

as part of a forall statment and the element extra doesn't exist in one of the feeditems I am iterating through in the forall condition then I get an error.

 

I think I need some kind of statment like:

 

if ($feeditem->getElementsByTagName('extra')  ISN'T NULL)

 

But don't know how to formulate it. Please help. Thanks.

Link to comment
https://forums.phpfreaks.com/topic/177963-domdocument-parsing/
Share on other sites

SORRY I was wrong, I haven't got it working.

 

basically when 'extra' isn't detected by getelementsbetagname I get a non-object error trying Tenyon's and "Can't use method return value in write contex" with yours Chronister.

 

So I need the if statement to specify that it isn't a non-object, I think?

Link to comment
https://forums.phpfreaks.com/topic/177963-domdocument-parsing/#findComment-938355
Share on other sites

Sorry here's the code chunk:

 

if (!empty($feeditem->getElementsByTagName('extra'))){
$extra = $feeditem->getElementsByTagName('extra');
        $extraname = $extra->item(0)->getAttribute('name');
        }

 

Code works fine if the DOMdocument has an 'extra' element in each of the $feeditems. Your advice is really appreciated.

Link to comment
https://forums.phpfreaks.com/topic/177963-domdocument-parsing/#findComment-938364
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.