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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:00:41+00:00 2026-06-12T17:00:41+00:00

I have this XML <STOREITEMS> <CREATED value=Tue Oct 9 5:30:01 BST 2012> <CATEGORY id=442

  • 0

I have this XML

<STOREITEMS>
  <CREATED value="Tue Oct 9 5:30:01 BST 2012">
    <CATEGORY id="442" name="Hen And Stag Nights"></CATEGORY>
    <CATEGORY id="69" name="Games"></CATEGORY>
    <CATEGORY id="252" name="Love Zone"></CATEGORY>
    <CATEGORY id="202" name="Spotlight  Items"></CATEGORY>
  </CREATED>
</STOREITEMS>

I need to get the Category – name attribute with PHP

So far I have this

$xml = simplexml_load_file("http://www.dropshipping.co.uk/catalog/xml_id_multi_info.xml");

foreach($xml->CATEGORY['name']->attributes() as $category)    
{    
    echo $category; 
}

This however returns Fatal error: Call to a member function attributes() on a non-object

Any ideas?
Thank you.

  • 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-12T17:00:42+00:00Added an answer on June 12, 2026 at 5:00 pm

    The CATEGORY nodes are nested inside the CREATED node, so you’d need to access it there, and accessing CATEGORY['name']->attributes() makes no sense, since that would try to access non-existent attributes on the name attribute of the first CATEGORY node.

    So do you want to retreive the name attribute values of all CATEGORY nodes, or all CATEGORY nodes, or maybe only those CATEGORY nodes that have a name attribute?

    All CATEGORY nodes:

    foreach($xml->CREATED->CATEGORY as $category)
    {
        echo $category['name'] . '<br />';
    }
    

    Only the CATEGORY nodes name attributes:

    foreach($xml->xpath('//CATEGORY/@name') as $name)
    {
        echo $name . '<br />';
    }
    

    Only the CATEGORY nodes that have a name attribute:

    foreach($xml->xpath('//CATEGORY[@name]') as $category)
    {
        echo $category['name'] . '<br />';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have XML like this: <exam> <section name=SampleSection1> <attributes> <variable_name data_type=String value=SCORE/> </attributes> <item
I have this XML: <root> <data name=lnkViewResultResource1.Text xml:space=preserve> <value>bekijk de resultaten</value> </data> <data name=lnkVoteResource1.Text
I have this xml from which I am trying to grab the value in
I have this xml <products> <product> <name>Demo</name> </product> <product> <name>Black Beauty III</name> <description>Beautiful les
I have this xml file which has text init. i.e Hi my name is
Suppose I have some XML like this: <section name=SampleSection> <item name=ScoredItem1> <attributes> <scored data_type=boolean
I have this xml file - payload.xml <Remoting><Response> <Controller id=c> <Messages/> <StructData name=Root> <F
I have this xml file: <test time=11.11.2011 11:11 > <field type=one value=10/> <field type=two
I have this XML structure: <numb> <variable> <name>john</name> <age>12</age> </variable> <variable> <name>janet</name> <age>10</age> </variable>
I have this XML: <RECEIPT receiptDate=2012-02-10T12:46:26.661Z submissionFile=E.coli_ENT_WS.submission.xml success=false> <EXPERIMENT alias=ENT 23 status=PUBLIC/> <EXPERIMENT alias=WS

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.