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

The Archive Base Latest Questions

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

Ok guys I’m using xml to store page information for a dynamic website. I

  • 0

Ok guys I’m using xml to store page information for a dynamic website. I need to figure out a way to take a variable(file name) and pull the related node and parse that information. so basically here’s my XML structure…

<SITE>

<PAGE>
<FILENAME>sub.php</FILENAME>
<DESCRIPTION>this is an example sub page</DESCRIPTION>
<TITLE>NOH Sub page</TITLE>
<PARENTS>
 <PARENT>What is NOH</PARENT>
</PARENTS>
</PAGE>

<PAGE>
<FILENAME>about.php</FILENAME>
<DESCRIPTION>description description description </DESCRIPTION>
<TITLE>About Us</TITLE>
<PARENTS>
 <PARENT>Company</PARENT>
 <PARENT>People</PARENT>
</PARENTS>
</PAGE>

</SITE>

Is there a way to use SimpleXML and PHP to take a variable say.. ‘sub.php’ and say I want the node where filename = ‘sub.php’, and then be able to parse that node(page) for needed info. Thanks!

Update, where I’m confused is…
i have this function

function getPage($pagePath){

$file = "includes/sitestructure.xml";
$xml = simplexml_load_file($file);  
return print_r($xml-xpath(PAGE/FILENAME));  
}

but my xpath doesn’t work, and I’m not sure how to logically get the info I need.. I know how to normally parse XML with PHP but not how to specify a specific node by comparing it to a variable then parse it.

  • 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:33:26+00:00Added an answer on May 27, 2026 at 11:33 am
    $xml-xpath(PAGE/FILENAME)
    

    This is broken in several ways, but this is an XPath question not a PHP syntax one.


    You want to get the PAGE element(s) which contain a FILENAME of your chosen file name. To do that in XPath, a predicate can be used.

    PAGE[FILENAME="sub.php"]
    

    In your PHP code that might look like

    $pages = $xml->xpath('PAGE[FILENAME="sub.php"]');
    $first_page = $pages[0];
    echo $first_page->TITLE; // NOH Sub page
    

    The important point here is the use of the predicate to filter the result to only the page element(s) that you want.

    • http://www.w3.org/TR/xpath/#predicates
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Guys, I am using dynamic programming approach to solve a problem. Here is a
Guys could any one point it out to me a link to web page
Guys im in need of a way to sort my posts by views, rating,
guys i have an xml in an URL and i need to parse that
Guys, I am using SQL Server 2000 and executing the sp_columns stored procedure to
guys which text editor is good for Rubyonrails? i m using Windows and i
guys i have a xml file which is like this: <Point TestFlag=0 id=1 name=Conversation
guys, I'm trying to realize viewing comments on internet portal and I'm using UITableView.
guys i got a php file that use it as xml for a flash
Guys i have a textview which i need it to be blinking please help

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.