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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:19:56+00:00 2026-05-21T18:19:56+00:00

I have an XML file that looks like this: <rss> <channel> <title>title</title> <link>link</link> <description>description</description>

  • 0

I have an XML file that looks like this:

<rss>
    <channel>
        <title>title</title>
        <link>link</link>
        <description>description</description>
        <item>
            <title>title 1</title>
            <sort>1</sort>
        </item>
        <label>
            <title>LABEL 1</title>
            <sort>2</sort>            
        </label>
        <item>
            <title>title 2</title>
            <sort>3</sort>
        </item>
        <label>
            <title>LABEL 2</title>
            <sort>4</sort>            
        </label>
        <item>
            <title>title 3</title>
            <sort>5</sort>
        </item>
        <template>3</template>
    </channel>
</rss>

I’m using SimpleXML and I need to do a foreach on the combined list of ‘item’ and ‘label’ nodes, ignoring the rest of the ‘channel’ children.

I was using:

foreach($feed->channel->item as $item) { }

…and labels were added as:

<item type="label">
    <title>LABEL 1</title>
</item>

…but the consumer of the file I’m building is expecting the node for labels.


UPDATE!

As the question didn’t get posted (need a title!) and I found the answer on my own in the meantime here’s what I did:

/* Search for items and labels */
$result = $iFeed->xpath('channel/*[name()="item" or name()="label"]');

foreach($result as $item) {
   // boom
}
  • 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-21T18:19:57+00:00Added an answer on May 21, 2026 at 6:19 pm

    I think you can also use the | operator. This combines the results of multiple XPath queries.

    $result = $root->xpath('channel/item|channel/label');
    

    It looks like it also preserves the ordering of the nodes, so the nodes are returned in this order: “item, label, item, label, item” (as opposed to “item, item, item, label, label”).

    • 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 this <library> <book> <title>Title</title> <author>author</author> <price>20</price>
I have a XML file that looks like this <Licence> <Name>Test company</Name> <Version>1.1.1.1</Version> <NumberOfServer>2</NumberOfServer>
I have an XML file that looks like this. <Almond> Roasted Almonds,Almond Extract,Almond Sauce,Almond
I have an XML file that looks like this. <collections id=my collections> <category id=my
I have an xml file that looks like this; <Employee> <EmployeeName>Burt Reynolds</EmployeeName> <EmployeeTitle>Bad Ass</EmployeeTitle>
--edited for clarity (hopefully) I have an XML file that looks something like this:
Currently, I have an xml file that looks like this... <ArrayOfService> <Service> <Name> Something
I have an xml file that looks like this <step> <id>3</id> <backid>1</backid> <question>Are you
Let's say I have a file-system that looks a little something like this: C:\stuff\build.xml
I have an XML file that starts like this: <Elements name=Entities xmlns=XS-GenerationToolElements> I'll have

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.