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

  • SEARCH
  • Home
  • 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

Related Questions

I have this simple hello world version of a google map api javascript v3
I have this Javascript: var signUp = { share: function(response) { alert('hello'); } }
Hello I have been having trouble with this for a while now. I have
Hello I have a string in PHP $string = ...................blah blah blah.................. where the
Hello i have this form filling javascript: function onLine(code,nn) { document.writeform.bericht.value+=code; document.writeform.bericht.focus(); document.writeform.nickname.value+=nn; write1();
Hello I have this list that i am working on. When i move the
I have a REST API which accepts XML in HTTP Posts. When I send
Hello I know all about http://www.php.net/manual/en/function.http-build-query.php to do this however I have a little
I have this syntax which works (since it's from the API, pretty much) <%
I have been building an API which returns XML code. For example, the API

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.