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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:39:27+00:00 2026-05-14T00:39:27+00:00

I am using php’s simple xml and xpath to parse an rdf xml file

  • 0

I am using php’s simple xml and xpath to parse an rdf xml file and am struggling to get a list of all the rdf:about values.

Any advice?

  • 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-14T00:39:27+00:00Added an answer on May 14, 2026 at 12:39 am

    There seems to be an issue when using SimpleXml with namespaced attributes prior to PHP5.3. Basically, anything with a : will be dropped when converted to an object property of a SimpleXml element. The following will do, but feels hackish to me:

    $rdf = str_replace('rdf:about', 'rdf_about', $rdf);  
    $rdf = new SimpleXMLElement($rdf);
    foreach($rdf->xpath('//@rdf_about') as $node) {
      echo $node, PHP_EOL;
    }
    

    See here:

    • http://groups.google.com/group/comp.lang.php/browse_thread/thread/d2a9b29ee21f7403/c6b24b6d398ece2c

    You could use DOM instead of SimpleXml:

    $dom = new DomDocument;
    $dom->loadXml($rdf);
    $xph = new DOMXPath($dom);
    $xph->registerNamespace('rdf', "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
    foreach($xph->query('//@rdf:about') as $attribute) {
        echo $attribute->value, PHP_EOL;
    }
    

    But, I suggest using a dedicated library for this over SimpleXml or DOM:

    • http://arc.semsol.org/docs/v2/parsing
    • http://www.seasr.org/wp-content/plugins/meandre/rdfapi-php/doc/
    • http://librdf.org/raptor/
    • http://phpxmlclasses.sourceforge.net/show_doc.php?class=class_rdf_parser.html

    And here’s a blog post about the parsers:

    • http://www.wasab.dk/morten/blog/archives/2004/05/31/easy-rdf-parsing-with-php
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using PHP and MySQL I'm trying to get all the distinct values out the
Using PHP, how do I get an entire subset of nodes from an XML
Using PHP and preg_match_all I'm trying to get all the HTML content between the
Using PHP's ReflectionClass. Is this possible? I want to get a list of methods
Using PHP, it's possible to read off the contents of a file using fopen
Using PHP, How to identify that the string is a path to any file?
Using PHP, I have a simple database that may store multiple items with the
Using PHP (other languages, using common built-ins are welcome), how can I get a
Using PHP 5.2.6 in XAMPP : I read about sql injections here and tried
Using php or javascript I want to get the title of the page Any

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.