[prog] implementing XML schema in php

Conor Daly conor.daly-linuxchix at cod.homelinux.org
Thu Apr 6 07:16:23 EST 2006


Hi all,

I'm working on implementing an XML schema in php.  I'm working against an
Ingres database using a 'dtd' table and an 'xml' table.  The dtd table
contains 'element' and 'attlist' data while the xml table contains the
columns: 'id' 'tag' 'attr' 'att_value' where 'id' identifies a particular
xml record, 'tag' is the xml 'element', 'attr' is the xml 'attlist'
attribute and 'att_value' is the data associated with that tag/attrib
pair.  Each tag/attrib pair occupies one row of the xml table so a record
will occupy multiple rows.

I've got to the point where my php will display the dtd, the xml layout of
the dtd and a form for input of data into a record defined by the dtd.  It
will also read existing records, update them and insert new records.  The
only thing left to do {apart from all the other things that are left to
do!} is to allow the input of multiple instances of some tag for a single
record.   For example, the structure:

<ID name='maxfall'>
  <People Author='Me' Used_by='QC Group'>
  </People>
  <Program Purpose='generate rainfall rates from minute data'>
  </Program>
  <Data>
    <Files>
      <Generated name='maxfall_nnn.out'>
      </Generated>
      <Generated name='maxfall_nnn.err'>
      </Generated>
      <Used name='maxfall.conf' source='user>
      </Used>
    <Tables>
      <Used name='raw_automin' source='agi data'>
      </Used>
      <Used name='raw_autohr' source='agi data'>
      </Used>
    </Tables>
    </Files>
  </Data>
</ID>

contains two instances of <Used> or <Generated> as subtags of other
tags.  Currently my php can display this if the appropriate number of rows
exist in the xml table but has no means of adding an extra blank
tag/attrib set into the form.  The tag/attrib display function is a
recursive one that looks like this:

function displayDtdData($tagvalue, $tag, $tagnum)
{ // gets and displays attributes and tags for a DTD
  // recursive function, walks the list of tags

  global $level;

//  echo "Displaying Record: $tagvalue<br>";
//       rowSep();

  $subtaglist=array();

       for ($i=1; $i<$level; $i++)
       { // Indent each tag level
         fieldSep();
       } // End for()

       echo "$tag";
       getDtdAttrib($tag);
       getDtdAttribData($tagvalue, $tag);
       displayDtdAttribData($tagvalue,$tag);
       $subtaglist=getDtdSubtags($tag);
       rowSep();
       $level++;
       for($subtag=1;$subtag<=$subtaglist[0]; $subtag++)
       { // Recursive call for each sub tag
//       echo "Subtag: $subtag; $subtaglist[$subtag]<br>";
         fieldSep();
         displayDtdData($tagvalue, $subtaglist[$subtag], $subtag);
       } // End for()
       $level--;

  return(0);
} // End function displayDtdData()

Rather than trying to keep track of which tag/attrib sets I've displayed,
I'm using in displayDtdAttribData():

     echo "<input type=\"TEXT\" name=\"$tableid.$tagvalue.$tagg.$attr\" value=\"";
  
to generate a 'label_id_tag_attr' $_POST variable for each tag/attrib
pair.  This allows the php to remain simple since I can just parse an
array_keys($_POST) to identify data to store.  Now, would there be a
simple way to add an 'extra tag' button to the form?  Is every button in
php a 'Submit' for the whole page/form?  Or do I end up having to track
everything???


Conor
-- 
Conor Daly <conor.daly at cod.homelinux.org>
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/G/S/O d+(-) s:+ a+ C++(+) UL++++ US++ P>++ L+++>++++ E--- W++ !N
PS+ PE Y+ PGP? tv(-) b+++(+) G e+++(*) h-- r+++ z++++ 
------END GEEK CODE BLOCK------
http://www.geekcode.com/ http://www.ebb.org/ungeek/


More information about the Programming mailing list