function Transform($node) { $name = $node->name(); // table name $fields = array(); $subtables = array(); foreach ($node->children() as $child) { if (substr($child->name(), -3) == 'Ref') { // We need to look through the reference, and see if we can find it's unique identifier (is it a ListID? a FullName? a TxnID?) $fields[substr($child->name(), 0, -3) . '_ListID'] = array('link!'); } else { if ($child->childCount()) { $child->setName($node->name() . '_' . $child->name()); $fields[$child->name() . '_qbID'] = array(QUICKBOOKS_DRIVER_SQL_INTEGER); $child->addChild(new QuickBooks_XML_Node($child->name() . '_qbID'), true); $subtables[] = $child; } else { $fields[$child->name()] = array($child->data()); } } } print 'name: ' . $name . "\n"; print_r($fields); print "\n"; foreach ($subtables as $node) { Transform($node); } }
function Script($n) { if ($n->hasChildNodes()) { $i = 0; while ($i < $n->childNodes->length) { $cur = $n->childNodes->item($i); if ($cur->nodeType == XML_DOCUMENT_NODE || $cur->nodeType == XML_ELEMENT_NODE) { $curname = $cur->nodeName; if (substr($curname, 0, 4) == "txs:") { $xpath = new DOMXPath($n->ownerDocument); $xpath->registerNameSpace("txs", "http://www.agencexml.com/txs"); $xpath->registerNameSpace("xsl", "http://www.w3.org/1999/XSL/Transform"); if ($cur->getAttribute("node") != '') { if ($xpath->query($cur->getAttribute("node"), $cur)->length == 0) { $curname = "dummy"; } } else { if ($xpath->query("ancestor::xsl:stylesheet", $cur)->length != 0 || $xpath->query("ancestor::txs:model", $cur)->length != 0) { $curname = "dummy"; } } } switch ($curname) { case "txs:load": Load($cur); break; case "txs:save": Script($cur); Save($cur); break; case "txs:transform": Script($cur); Transform($cur); continue 2; case "txs:httprequest": Httprequest($cur); break; case "txs:call": Call($cur); continue 2; case "txs:fileexists": FileExists($cur); break; case "txs:folderexists": FolderExists($cur); break; case "txs:from-model": Script($cur); FromModel($cur, $cur); break; case "txs:process": Process($cur); break; default: Script($cur); } } $i++; } } }