février 17, 2003
Proposed XML structure for comments

Here's the proposed XML structure for comments to NW entries:

<nwcomments nwentryurl="http: ....">
                <name>Steph Troeth</name>
        I was on the bridge and I took this photograph of the river ....
                <name>Daisy Cow</name>
         This area has very nice grass to eat. Right near a train line where I can watch the trains go too. Nice place to visit.

The previd element is optional. This is used for threading purposes (based on issue raised by Delphine). If the previd doesn't exist, we assume we are looking at a new thread.

Posted by steph at 06:18 PM
février 12, 2003
Parsing NW XML Files

Hi everyone,

I have been experimenting with parsing a typical index.xml file to transform it into a form where some elements are editable. I'm doing this with an event based parser (where you define how you handle the start, end elements, and characters in between, the same as in previous examples), and also with class_path_parser.

The class_path_parser method is more concise and perhaps better suited for our purposes:

<? print "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<title>Parsing NW XML files</title>

// a map so that xml elements are transformed into human readable names
// on print
$map_array = array(
    "nwregion" => "Région",
    "nwdpt"  => "Département",
    "nwcanton"  => "Canton",
    "nwtitle" => "Titre",
    "nwlogo" => "Logo",
    "nwmetadesc" => "Metadesc",
    "nwkeywords" => "Keywords",
    "nwurl" => "URL",
    "nwcreadate" => "Creation date",
    "nwmoddate" => "Last modified date",
    "nwauteur" => "Auteur",
    "nwemail" => "Email"

// handle none editable elements
function nonEditHandler($name,$attribs,$content) {
  global $map_array;
  $pattern = "/<$name>(.*)<\/$name>/";
  $replacement = "$1";
  $content = preg_replace($pattern,$replacement,$content);

  print "<strong>$map_array[$name]:</strong> $content<br>\n";

// handle elements within nwtexte
function nwtexteHandler ($name,$attribs,$content) {
  global $map_array;
  $pattern = "/<$name>(.*)<\/$name>/";
  $replacement = "$1";
  $content = preg_replace($pattern,$replacement,$content);

  print "<strong>$map_array[$name]:</strong> <input size=\"70\" type=\"text\" value=\"$content\"><br />\n";

// handle elements where we want the information raw as it is
function rawHandler ($name,$attribs,$content)

  $pattern = "/<$name>/";
  $replacement = "";
  $content = preg_replace($pattern,$replacement,$content);
  $pattern = "/<\/$name>/";
  $replacement = "";
  $content = preg_replace($pattern,$replacement,$content);

  print "<textarea cols=\"70\" rows=\"10\">$content</textarea>\n";

$parser = new Path_parser();

//handle all our elements

print "<form method=\"post\" action=\"submitXML.php\">\n";

// currently we pass this a static file name, later on we'll grab it from
// a url
if(!$parser->parse_file("index.xml")) {

print "<p><input type=\"submit\" name=\"submitXML\" value=\"Submit changes\"></p>\n";

print "</form>\n";


This is not currently on the live server yet. The obvious problem is we have to know the structure of the XML file. If the XML file format changes, this program will have to be changed too.

I'm working on using Sabletron XSL/PHP for templating, in order to save modified files back into the XML format .

Posted by steph at 01:09 AM