Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 408097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:39:33+00:00 2026-05-12T17:39:33+00:00

Hello I have an api response in xml format with a series of items

  • 0

Hello I have an api response in xml format with a series of items such as this:

<item>
<title>blah balh</title>
<pubDate>Tue, 20 Oct 2009 </pubDate>
<media:file  date="today" data="example text string"/>
</item>

I want to use DOMDocument to get the attribute “data” from the tag “media:file”. My attempt below doesn’t work:

$xmldoc = new DOMDocument();
$xmldoc->load('api response address');
foreach ($xmldoc->getElementsByTagName('item') as $feeditem) {
$nodes = $feeditem->getElementsByTagName('media:file');
$linkthumb = $nodes->item(0)->getAttribute('data');
}

What am I doing wrong? Please help.

EDIT: I can’t leave comments for some reason Mark. I get the error

 Call to a member function getAttribute() on a non-object

when I run my code. I have also tried

$nodes = $feeditem->getElementsByTagNameNS('uri','file');
$linkthumb = $nodes->item(0)->getAttribute('data');

where uri is the uri relating to the media name space(NS) but again the same problem.

Note that the media element is of the form not I think this is part of the problem, as I generally have no issue parsing for attibutes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:39:34+00:00Added an answer on May 12, 2026 at 5:39 pm

    The example you provided should not generate an error. I tested it and $linkthumb contained the string “example text string” as expected

    Ensure the media namespace is defined in the returned XML otherwise DOMDocument will error out.

    If you are getting a specific error, please edit your post to include it

    Edit:

    Try the following code:

    $xmldoc = new DOMDocument();
    $xmldoc->load('api response address');
    foreach ($xmldoc->getElementsByTagName('item') as $feeditem) {
        $nodes = $feeditem->getElementsByTagName('file');
        $linkthumb = $nodes->item(0)->getAttribute('data');
        echo $linkthumb;
    }
    

    You may also want to look at SimpleXML and Xpath as it makes reading XML much easier than DOMDocument.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 244k
  • Answers 244k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Maybe there are times you just shouldn't make a recommendation?… May 13, 2026 at 8:04 am
  • Editorial Team
    Editorial Team added an answer INCOSE is an excellent resource for this sort of question.… May 13, 2026 at 8:04 am
  • Editorial Team
    Editorial Team added an answer I think you need to do that with a fake… May 13, 2026 at 8:04 am

Related Questions

I have a PHP script that connects to an api and posts information to
I know this is a common error, but bear with me. I've pursued the
I'm using Exchange Web Service exposed from exchange 2007 SP1 server to create emails
Say I have a vector: (def data [Hello World Test This]) And I want

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.