phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] CVS: phpgwapi/doc/xml xmltool_tester.php,NONE,1.1 xml


From: Dan Kuykendall <address@hidden>
Subject: [Phpgroupware-cvs] CVS: phpgwapi/doc/xml xmltool_tester.php,NONE,1.1 xmltool_tester.xml,NONE,1.1
Date: Sat, 21 Sep 2002 11:01:34 -0400

Update of /cvsroot/phpgroupware/phpgwapi/doc/xml
In directory subversions:/tmp/cvs-serv30553

Added Files:
        xmltool_tester.php xmltool_tester.xml 
Log Message:
help people undestand this stuff better

--- NEW FILE ---
<?php
include ('../inc/class.xmltool.inc.php');

/* This is just a funky array I created to test with */
$subarray1['count'] = Array('one','two','three');
$subarray2['count'] = Array('four','five','six');
$myarr['red'] = 'base color';
$myarr['yellow'] = 'base color';
$myarr['blue'] = 'base color';
/* I add an indexed sub-array as an example */
/* for how it will properly handle putting this in xml */
$myarr['green']['mix']=Array('yellow','blue');
$myarr['orange']['mix']=Array('yellow','red');
/* and even an indexed sub-array can have more nesting */
/*       all can loop on forever */
$myarr['orange']['wax'][]=$subarray1;
$myarr['orange']['wax'][]=$subarray2;
$myarr['jack']['jill']['harry']['met']['sally'] = 'hello';
$myarr['jack']['jill']['harry']['met']['joe'] = '';
/* I even toss in a class object which will be put into xml */
/* Since I only have the xmltool class handy, I used an instance of that */
$myarr['somenode'] = new xmltool('node', 'PHPGW');

echo "<html><body>\n";
$nav = 'navigation: <a href="#start">initial array</a> | <a 
href="#export_xml">export_xml</a> | <a href="#import_xml">import_xml</a> | <a 
href="#export_var">export_var</a> | <a 
href="#export_struct">export_struct</a><br>'."\n";

echo '<a name="start">';
echo $nav;
echo "This is the result of <code>print_r(\$myarr); </code>\$myarr is the 
multi-dimensional array we which have defined in the file.\n";
echo "note: notice the last element of the array is an object. xmltool will 
handle this as well\n";
echo "<pre>\n";
print_r($myarr);
echo "</pre>\n";

/* Now to auto-convert to an xmltool object */
echo '<hr>';
echo '<hr>';
echo '<a name="export_xml">';
echo $nav;
echo "The array has been auto converted to XML. This can be done in any of the 
following three ways<br>\n";
echo "Long method:<br>\n<code>\n \$doc = new xmltool();<br>\n 
\$doc->import_var('myarr',\$myarr,True);<br>\n \$xml_result = 
\$doc->export_xml();<br>\n</code><br>\n";
echo "Immediate export method:<br>\n<code>\n \$doc = new xmltool();<br>\n 
\$xml_result = 
\$doc->import_var('myarr',\$myarr,True,true);<br>\n</code><br>\n";
echo "Super quick method which uses the var2xml() companion 
function:<br>\n<code>\n \$xml_result = \$var2xml(\$myarr);<br>\n</code><br>\n";

$doc = new xmltool();
$xml_result = $doc->import_var('myarr',$myarr,True,true);
$somexmldoc = $xml_result;
echo "The gnerated XML doc:\n";
echo "<pre>\n";
echo htmlentities($xml_result);
echo "</pre>\n";

echo '<hr>';
echo '<hr>';
echo '<a name="import_xml">';
echo $nav;
echo "Now we look at importing an XML doc. We can use the one we just created 
as an example.\n";
echo "<br>\n<code> \$doc = new xmltool();<br>\n 
\$doc->import_xml(\$xml_result);<br>\n</code><br>\n";

$doc = new xmltool();
$doc->import_xml($xml_result);

echo "This is the result of <code>print_r(\$doc);</code> which shows the object 
tree\n";
echo "<pre>\n";
print_r($doc);
echo "</pre>\n";

$cnode = new xmltool('node','newnode');
$cnode->import_var('blah',$myarr);
echo "<br>\nThis is the result of <code>print_r(\$cnode);</code> which shows 
the object tree\n";
echo "<pre>\n";
print_r($cnode);
echo "</pre>\n";

//$doc->data->data[3]->import_xml($xml_result);
//$doc->data->data[3]->import_var('blah',$myarr);
$xml_result = $doc->export_xml();

echo '<hr>';
echo '<hr>';
echo "The generated XML doc:\n";
echo "<pre>\n";
echo htmlentities($xml_result);
echo "</pre>\n";

echo '<hr>';
echo '<hr>';
echo '<a name="export_var">';
echo $nav;
echo "We can export to an array like this<br>\n";
echo "<code>\$result_array = \$doc->export_var();<br>\n</code><br>\n";

$result_array = $doc->export_var();

echo "This is the result of <code>print_r(\$result_array);</code>\n";
echo "<pre>\n";
print_r($result_array);
echo "</pre>\n";

echo '<hr>';
echo '<hr>';
echo '<a name="export_struct">';
echo $nav;
echo "We can export to a struct like this<br>\n";
echo "<code>\$result_struct = \$doc->export_struct();<br>\n</code><br>\n";

$result_struct = $doc->export_struct();

echo "This is the result of <code>print_r(\$result_struct);</code>\n";
echo "<pre>\n";
print_r($result_struct);
echo "</pre>\n";
echo '<br>';
echo '<br>';
echo '<br>';
echo '<br>';
echo '<br>';
echo '<br>';
echo '<br>';
echo '<br>';
echo '<br>';
echo '<br>';
echo '<br>';
echo '<br>';
echo '<br>';
echo '<br>';
echo '<br>';
echo '<br>';
echo '<br>';
echo '<br>';
echo '<br>';
echo '<br>';
echo '<br>';
echo '<br>';
echo '<br>';

echo "</body></html>";
?>

--- NEW FILE ---
<?xml version="1.0"?>
<myarr>
  <red>base color</red>
  <yellow>base color</yellow>
  <blue>base color</blue>
  <green>
    <mix>yellow</mix>
    <mix>blue</mix>
  </green>
  <orange>
    <mix>yellow</mix>
    <mix>red</mix>
    <wax>
      <count>one</count>
      <count>two</count>
      <count>three</count>
    </wax>
    <wax>
      <count>four</count>
      <count>five</count>
      <count>six</count>
    </wax>
  </orange>
  <jack>
    <jill>
      <harry>
        <met>
          <sally>hello</sally>
          <joe></joe>
        </met>
      </harry>
    </jill>
  </jack>
  <somenode>
                
<![CDATA[PHP_SERIALIZED_OBJECT:O:7:"xmltool":10:{s:9:"node_type";s:4:"node";s:8:"comments";a:0:{}s:10:"xmlversion";s:3:"1.0";s:7:"doctype";a:0:{}s:9:"root_node";N;s:4:"name";s:5:"PHPGW";s:4:"data";N;s:9:"data_type";N;s:10:"attributes";a:0:{}s:12:"indentstring";s:2:"
  ";}]]>
        </somenode>
</myarr>





reply via email to

[Prev in Thread] Current Thread [Next in Thread]