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 8512807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:22:59+00:00 2026-06-11T04:22:59+00:00

This is a follow-on question to this: Getting XML attributes in PHP I’m struggling

  • 0

This is a follow-on question to this:
Getting XML attributes in PHP

I’m struggling to get element values with a namespace prefix. See this example from here: http://itunes.apple.com/us/rss/toppaidapplications/limit=10/genre=6014/xml

<im:image height="53">http://a2.mzstatic.com/us/r1000/114/Purple/v4/bc/0e/86/bc0e8619-5d48-1efe-2ac3-662696fb9a34/mzl.bimldzcn.53x53-50.png</im:image>          
<im:image height="75">http://a3.mzstatic.com/us/r1000/114/Purple/v4/bc/0e/86/bc0e8619-5d48-1efe-2ac3-662696fb9a34/mzl.bimldzcn.75x75-65.png</im:image>

If I try and reference the element using $e->im:image I get the following error:

PHP Parse error:  syntax error, unexpected ':' 

$e->’im:image’ gives me:

PHP Parse error:  syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_STRING or T_VARIABLE or '{' or '$' 

Any suggestions?

UPDATE: I’ve edited the question title which was misleading. It’s actually element values with a namespace prefix (not attributes) that I’m interested in.

  • 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-06-11T04:23:00+00:00Added an answer on June 11, 2026 at 4:23 am

    When using SimpleXML (as suggested by your previous question) you have to use the children() method to fetch all child elements of a certain namespace, same with attributes().

    e.g.

    <?php
    define('URI_RSS', 'http://itunes.apple.com/rss');
    $feed = new SimpleXMLElement(getData());
    
    foreach( $feed->entry as $entry ) {
        $attributes = $entry->id->attributes(URI_RSS);
        echo 'id[im:id]: ', $attributes['id'], "\n";
    
        $attributes = $entry->category->attributes(URI_RSS);
        echo 'category[im:id]: ', $attributes['id'], "\n";
    
        $imElements = $entry->children(URI_RSS);
        foreach( $imElements as $name=>$c ) {
            echo $name, '=', $c, "\n";
        }
    }
    
    function getData() {
        return <<< eot
    <?xml version="1.0" encoding="utf-8"?>
    
        <feed xmlns:im="http://itunes.apple.com/rss" xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
            <id>someid</id><title>some title</title><updated>2012-09-10T02:12:06-07:00</updated><link rel="alternate" type="text/html" href="http://link1"/><link rel="self" href="http://link12"/><icon>http://iconlink1</icon><author><name>some name</name><uri>http://uri</uri></author><rights>all rights wronged</rights>
    
                <entry>
                    <updated>2012-09-10T02:12:06-07:00</updated>
    
                        <id im:id="123456789" im:bundleId="a.bundle.id">http://id</id>
    
                        <title>some title</title>
    
                        <summary>This is the summary.
    
    A short text summarizing the complete article
    </summary>
    
                        <im:name>imname</im:name>
    
                        <link rel="alternate" type="text/html" href="http://alternate"/>
    
                        <im:contentType term="Application" label="Application"/>
    
                        <category im:id="7890" term="example" scheme="http://scheme" label="example"/>
    
                        <link title="Preview" rel="enclosure" type="image/jpeg" href="http://preview" im:assetType="preview"><im:duration>0</im:duration></link>
    
                        <im:artist href="http://artist">sample artist</im:artist>
    
                        <im:price amount="0.99000" currency="USD">$0.99</im:price>
    
                        <im:image height="53">http://1.png</im:image>
    
                        <im:image height="75">http://2.png</im:image>
    
                        <im:image height="100">http://3.png</im:image>
    
                        <rights>all rights wronged</rights>
    
                        <im:releaseDate label="August 28, 2012">2012-08-28T00:00:00-07:00</im:releaseDate>
    
    
                        <content type="html">content
                        content
                        content
    </content>
    
                </entry>
            </feed>
    eot;
    }
    

    prints

    id[im:id]: 123456789
    category[im:id]: 7890
    name=imname
    contentType=
    artist=sample artist
    price=$0.99
    image=http://1.png
    image=http://2.png
    image=http://3.png
    releaseDate=2012-08-28T00:00:00-07:00
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a follow-up question to the following if you would like to see:
This is a follow up question from Team Foundation Server: Getting the Changeset Id
Hey guys. This is a follow-on from this question : After getting the right
This question is a follow up to my previous question about getting the HTML
this is the follow-up to my question about getting a div's content. the second
This is a follow up question from Calling constructor in return statement . This
This is a follow up question to a previous question I asked about calculating
This is a follow-on question from the one I asked here . Can constraints
This is a follow-up question to ASP.NET How to pass container value as javascript
This is a follow-up question to this question I asked earlier. Btw thanks Neil

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.