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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:00:29+00:00 2026-05-25T06:00:29+00:00

In this web page, I have a php script to recreate divs on the

  • 0

In this web page, I have a php script to recreate divs on the page based on XML data. The script is called directly from the HTML page inside <body> </body>.

<body>
 <div id="page" class="demo">
 </div>

 <?php
   // script for recreating divs calls SimpleXMLElement or DOMXPath
 ?>
</body>

When I get the XML nodes with SimpleXMLElement, there are no errors, the nodes are returned. When instead I try DOMXPath, there are errors.

This returns the nodes.

$nodes = new SimpleXMLElement('communities.xml', null, true);

foreach($nodes as $node) // loop through 
{
  //restore divs from node information      
}

This doesn’t return the nodes and gives errors.

$dom = new DOMDocument();
$dom->load('communities.xml');
$xpath = new DOMXPath($dom);
$nodes = $xpath->query('COMMUNITY');

foreach($nodes as $node) // loop through 
{
  //restore divs from node information      
}

To extend the script to get more information from the nodes I thought of using xpath. The additional information I want to show is: NAME: text to show for each url contained in the div (Google.com), URLC: url corresponding to the text (http://google.com). The XML file has nodes like this.

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<COMMUNITIES>
  <COMMUNITY ID="c000010">
    <NAME>New000010</NAME> 
    <TOP>50</TOP> 
    <LEFT>50</LEFT> 
    <WIDTH>150</WIDTH> 
    <HEIGHT>150</HEIGHT> 
    <URLS>
      <URL ID="u000038">
        <NAME>Google.com</NAME> 
        <URLC>http://google.com</URLC> 
      </URL>
    </URLS>
  </COMMUNITY>
</COMMUNITIES>

The strange problem is that elsewhere, in ajax calls from javascript functions I get information from the XML file with xpath without any problems. Why doesn’t the DOMXPath method work in that situation?

EDITS * NEW INFORMATION

Here is the php file called through ajax from the html page. This is where SimpleXMLElement works. But if I try to create a new DOMdocument() then call xpath. The new DOM document isn’t created.

<?php

function get_nodes() {
// load SimpleXML
/* $nodes = new SimpleXMLElement('communities.xml', null, true); */

$dom = new DOMDocument();
$dom->load('communities.xml');

// get document element  

$xpath = new DOMXPath($dom);
$nodes = $xpath->query("//COMMUNITY");

foreach($nodes as $node) // loop through 
{

        echo "<div id = '".$node['ID']."' class= 'comdiv ui-widget-content' style = 'top: ".$node->TOP."; left: ".$node->LEFT."; width: ".$node->WIDTH."; 

height: ".$node->HEIGHT.";'> \n";            echo "   <p class = 'comhdr editableText ui-widget-header'>".$node->NAME."</p>\n";

        echo "   <a href='#' onClick=\"delete_div('".$node['ID']."');\">Delete</a>&nbsp;&nbsp;\n";
        echo "   <a href='#' onClick=\"add_url('".$node['ID']."');\">Add URL</a>&nbsp;&nbsp;\n";

        echo "</div> \n";

        echo "<script type='text/javascript'>\n";
        echo "  $('#".$node['ID']."').resizable();\n";
        echo "  $('#".$node['ID']."').draggable();\n";
        echo "  $('#".$node['ID']."').draggable('option', 'handle', '.comhdr');\n";
        echo "</script>\n";

}
        echo "<script type='text/javascript'>\n";
        echo "  $('.comhdr').editableText();\n";
        echo "</script>\n";

   return;
}

echo get_nodes();

?>
  • 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-25T06:00:30+00:00Added an answer on May 25, 2026 at 6:00 am

    Had folder permission issues. The folder containing the XML did not have permission set for the script to write the updated XML.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have code like this in a web based file called 'view_file.php' to
I have a web page coded in PHP. This page is for posting a
I have used this code for extracting urls from web page.But in the line
I have a PHP script that works by calling items from a database based
I have a php script to retrieve data from a MysQL databse following an
I have a web page. When this web page is loaded, I want to
I have this label control in my web page <asp:Label ID=Label1 runat=server Text=test></asp:Label> And
I have a web page with swf file defined this way <object width=600 height=400
I have a web page that consists of a checkbox (parent) and on this
I have this web application using Spring Web Flow framework. In my main page

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.