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

  • Home
  • SEARCH
  • 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 723587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:07:30+00:00 2026-05-14T06:07:30+00:00

Thanks to AakashM, he led me in the right direction. For the question below,

  • 0

Thanks to AakashM, he led me in the right direction. For the question below, this is the xPath expression that led me the right way:

"//channel/item[category[@domain='http://www.somelink.com/?category=4']]"

Original post:

I have an XML feed that looks something like this (excerpt):

<channel>
  <title>Channel Name</title>
  <link>Link to the channel</link>

    <item>
      <title>Heading 1</title>
      <link>http://www.somelink.com?id=100</link>
      <description><![CDATA[ Text here ]]></description>
      <publishDate>Fri, 03 Apr 2009 10:00:00</publishDate>
      <guid>http://www.somelink.com/read-story-100</guid>
      <category domain="http://www.somelink.com/?category=4">Category 1</category>
    </item>

    <item>
      <title>Heading 2</title>
      <link>http://www.somelink.com?id=110</link>
      <description><![CDATA[ Text here ]]></description>
      <publishDate>Fri, 03 Apr 2009 11:00:00</publishDate>
      <guid>http://www.somelink.com/read-story-110</guid>
      <category domain="http://www.somelink.com/?category=4">Category 1</category>
    </item>

  <channel>

That’s the rough of it. I’m using this piece of PHP (excerpt):

$xml = simple_xml_load_file($xmlFile);
$xml->xpath($pattern);

Now I want to get all ITEM-nodes (with their children) based on that pesky “domain” attribute in the category node, but no matter what I try it does-not-work.

The closest I got was “//category[@domain= ‘http://www.somelink.com/?category=4‘]”

The expression I tried gave me this result:

 [0] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [domain] => http://www.somelink.com/?category=4
                )

            [0] => Category 1

 [1] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [domain] => http://www.somelink.com/?category=4
                )

            [0] => Category 1

The expression should contain all childrens of the two items in the example, but as you can see only the info in the category node is present, I want all the item nodes.

Any help would be highly appreciated.

  • 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-14T06:07:31+00:00Added an answer on May 14, 2026 at 6:07 am

    (Try and avoid using // when you know for sure the structure of your xml)

    So you want all item nodes which have a category child node which in turn has a domain attribute with a particular value:

    /channel/item[category[@domain='http://www.somelink.com/?category=4']]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thanks for looking at this question in advance. I'm using jQuery drag and drop
Thanks for looking at this question in advance. I am trying to order the
Thanks for the input on this question , I've decided to go with making
Thanks for taking the time to look at this question. Currently, I have a
Thanks to Insin for answering a previous question related to this one. His answer
Thanks for stopping by. this static analyser warning is annoying me here is my
Thanks for reading this. I have no idea why this is throwing a NullReferenceException
Thanks in advance for taking the time to read my question. I'm building an
Thanks in advance for any help on this, apologies if I'm being a glaring
Thanks to the help of those on SO, I have a great UISearchBar that

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.