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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:37:34+00:00 2026-05-27T11:37:34+00:00

<?xml version=1.0 encoding=utf-8?> <mainXML> <items> <item category=Dekorationer name=Flot væg description=Meget flot væg. Passer alle

  • 0
<?xml version="1.0" encoding="utf-8"?>
<mainXML>
    <items>
        <item category="Dekorationer" name="Flot væg" description="Meget flot væg. Passer alle stuer." price="149" />
        <item category="Fritid" name="Fodbold" description="Meget rund bold. Rørt af messi." price="600" />
    </items>
</mainXML>

How can i read this?

So i can make like a php loop that outputs the category, name and description for example?

I tried and started out with this:

    $doc = new DOMDocument();
    $doc->load( 'ex.xml' );

    $items = $doc->getElementsByTagName( "item" );
    foreach( $items as $item )
    {
        $categorys = $item->getElementsByTagName( "category" );
        $category = $categorys->item(0)->nodeValue;

        echo $category . " -- ";
    }
  • 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-27T11:37:34+00:00Added an answer on May 27, 2026 at 11:37 am

    category is an attribute (not a tag). See XMLWikipedia. To obtain it via the DOMElement, use getAttribute()Docs:

    foreach ($items as $item)
    {
        $category = $item->getAttribute('category');
        echo $category, ' -- ';
    }
    

    Same for description, just change the name of the attribute to obtain:

    foreach ($items as $item)
    {
        echo 'Category: ', $item->getAttribute("category"), "\n",
             'Description: ', $item->getAttribute("description"), ' -- ';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file that looks like <?xml version='1.0' encoding='UTF-8'?> <root> <node name=foo1
If I have one layout file => res/layout/item.xml : <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
I have a input file Main.xml <?xml version=1.0 encoding=utf-8 ?> <Employees> <Employee> <id name=id>1</id>
This is the code.. string.xml <?xml version=1.0 encoding=utf-8 ?> - <resources> - <string-array name=countries_array>
I am using following layout for my list view items. <?xml version=1.0 encoding=utf-8?> <TextView
I have the following XML Document: <?xml version=\1.0\ encoding=\UTF-8\?> <atom:entry xmlns:atom=\http://www.w3.org/2005/Atom\ xmlns:apps=\http://schemas.google.com/apps/2006\ xmlns:gd=\http://schemas.google.com/g/2005\> <apps:property
Here's the XML: <?xml version='1.0' encoding='UTF-8' standalone='yes' ?> <feed xmlns=http://www.w3.org/2005/Atom xmlns:dc=http://purl.org/dc/elements/1.1/> <title>Rated Images</title> <link
I have an getting an xml response on this format <?xml version=\1.0\ encoding=\utf-8\?>\r\n <PlatformResponse
I am trying to parse the following XML with javascript: <?xml version='1.0' encoding='UTF-8'?> <ResultSet>
This is my xhtml code : <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC -//W3C//DTD

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.