+++ /dev/null
-<?php\r
-// \r
-/**\r
- * This class provides the functionality to trace an xml tag \r
- */\r
-\r
-class XmlTagTrace\r
-{\r
- private $tagToTrace; // the xml tag to be collected\r
- private $tagToTraceLevel; // The level of the xml tag bo be collected/traced\r
- private $xmlString; // Xml data as string\r
- \r
- private $xmlTag; // temporary object to store XML object while reading xml array\r
- private $xmlTagState; // true or false if tracing tag is done\r
- private $myXmlCollection; // collection of the traced xml tag\r
- \r
- /**\r
- * Class Constructor: starts tracing a XML tag. It recieves a xml TagName and xml TagLevel\r
- * @param String $theXmlString XML data as String\r
- * @param String $theTagToTrace XML Tag to trace \r
- * @param String $theTagToTraceLevel Level of the XML tag to trace\r
- */\r
- function __construct($theXmlString,$theTagToTrace,$theTagToTraceLevel)\r
- {\r
- \r
- // set the XML data\r
- //$this->xmlString = $theXmlString;\r
- \r
- // set the tag to trace and the starting level\r
- $this->tagToTrace = $theTagToTrace;\r
- $this->tagToTraceLevel = $theTagToTraceLevel;\r
- \r
- // create XML tag Collection\r
- $this->myXmlCollection = new XmlTagCollection();\r
- \r
- // start tracing\r
- $this->traceXmlTag($theXmlString); \r
- } // __construct() end\r
-\r
- /**\r
- * Returns the XML tag Collection\r
- *\r
- */\r
- public function getCollection()\r
- {\r
- //get from here of from XmlTagCollection collection object???\r
- return $this->myXmlCollection->getXmlTagCollection();\r
- //return $this->myXmlCollection;\r
- //echo '<br>From '\r
- \r
- \r
- }// end getCollection()\r
- \r
- /**\r
- * Creates an XML parcer and Iterates through array\r
- *\r
- * @param unknown_type $theXmlString\r
- */\r
- private function traceXmlTag($theXmlString)\r
- {\r
- // create XML parser\r
- $p = xml_parser_create();\r
- \r
- // parse XML data into array\r
- xml_parse_into_struct($p, $theXmlString, $xmlVals, $xmlIndex);\r
- \r
- // free XML parser \r
- xml_parser_free($p);\r
- \r
- // initialize XML object ????\r
- //$myXmlTag = new XmlTag()\r
-\r
- \r
- // start looping xml array\r
- for($i = 0; $i < count($xmlVals); $i++) \r
- {\r
- // initialize XML data\r
- $theTagName='';\r
- $theTagType='';\r
- $theTagLevel='';\r
- $theTagValue='';\r
- $theTagAtrib = Array();\r
- \r
- // verify data before adding\r
- if (isset($xmlVals[$i]['tag']))\r
- {\r
- $theTagName = $xmlVals[$i]['tag'];\r
- }\r
- \r
- if (isset($xmlVals[$i]['type']))\r
- {\r
- $theTagType = $xmlVals[$i]['type'];\r
- }\r
- \r
- if (isset($xmlVals[$i]['level']))\r
- {\r
- $theTagLevel = $xmlVals[$i]['level'];\r
- }\r
- \r
- if (isset($xmlVals[$i]['value']))\r
- {\r
- $theTagValue = $xmlVals[$i]['value'];\r
- }\r
-\r
- if (isset($xmlVals[$i]['attributes']))\r
- {\r
- $theTagAtrib = $xmlVals[$i]['attributes'];\r
- } \r
- \r
- // set xml data\r
- $this->setXmlData($theTagName,$theTagType,$theTagLevel,$theTagValue,$theTagAtrib);\r
- \r
- \r
- } // end for loop xml array\r
- \r
- } // end traceXmlTag()\r
- \r
- /**\r
- * Recieves Xml data from each tag and determines if values should be collected \r
- * this to trace <P> and <div> tags \r
- *\r
- * @param String $theTagName\r
- * @param String $theTagType\r
- * @param String $theTagLevel\r
- * @param String $theTagValue\r
- * @param String $theTagAtrib\r
- */\r
- private function setXmlData($theTagName,$theTagType,$theTagLevel,$theTagValue,$theTagAtrib)\r
- {\r
- \r
- //echo '<br/>'.$this->tagToTrace;\r
- \r
- // verify also if the level is lower !!!!\r
- \r
- //echo '<br/>'.$theTagName;\r
- // verify if this data is from the xml tag being traced/collected\r
- if ($theTagName == $this->tagToTrace)\r
- {\r
- \r
- //echo '<br/>'.$theTagName.' TAG IS THE SAME';\r
- //echo '<br/>Value: '.$theTagValue.'';\r
- \r
- \r
- // if tag is complete. The tag has NO children\r
- if ($theTagType=='complete')\r
- {\r
- // create a XmlTag object\r
- $this->xmlTag = new XmlTag($theTagName,$theTagType,$theTagLevel,$theTagValue,$theTagAtrib);\r
- \r
- // tracing this tag is done. \r
- $this->xmlTagState = true;\r
- \r
- $this->xmlTag->setTagState(true);\r
- \r
- //echo '<br/>'.$theTagName.' TAG is complete !!!';\r
- \r
- //$this->xmlTag->toString();\r
- \r
- // add to collection\r
- $this->myXmlCollection->addXmlTagObject($this->xmlTag);\r
- \r
- // reset temp object\r
- $this->xmlTag = null;\r
-\r
- } // end if complete\r
-\r
- // if tag is open. tag do have children\r
- else if ($theTagType=='open')\r
- {\r
- // create a new XmlTag object\r
- $this->xmlTag = new XmlTag($theTagName,$theTagType,$theTagLevel,$theTagValue,$theTagAtrib);\r
- \r
- // tracing this tag is NOT done. \r
- $this->xmlTagState = false;\r
- \r
- //echo '<br/>'.$theTagName.' TAG is Open !!!';\r
- \r
- } // end if\r
-\r
- // if tag cdata. Getting data of the traced Tag, after any children data\r
- else if ($theTagType=='cdata')\r
- {\r
- // add value to traced tag \r
- // OJO !! This skips any child value \r
- $this->xmlTag->addToTagValue($theTagValue);\r
- \r
- // tracing this tag is NOT done. \r
- $this->xmlTagState = false;\r
- //echo '<br/>'.$theTagName.' TAG is cdata!!!';\r
- \r
- \r
- } // end if\r
-\r
- // if tag close. Getting data of the traced Tag is done\r
- else if ($theTagType=='close')\r
- {\r
- // add value of traced tag \r
- $this->xmlTag->addToTagValue($theTagValue);\r
- \r
- // tracing this tag is NOT done. \r
- $this->xmlTagState = true;\r
- \r
- $this->xmlTag->setTagState(true);\r
- //echo '<br/>'.$theTagName.' TAG is close!!!';\r
- \r
- //add to collection\r
- $this->myXmlCollection->addXmlTagObject($this->xmlTag);\r
- \r
- // reset temp object\r
- $this->xmlTag = null;\r
- \r
- } // end if\r
- \r
- \r
- }// end if tracing xml tag\r
-\r
- /*\r
- * if the tag is a children. the tagToTraceLevel is lower than the current TagLevel \r
- * this for all tags like <br/>, <b>, <i>, <u>, or even for <span> inside our traced tag\r
- */\r
- if ($this->tagToTraceLevel<$theTagLevel && (isset($this->xmlTag)))\r
- {\r
- // adding children data to tag as value \r
- $this->xmlTag->addChildTagAsValue($theTagName,$theTagType,$theTagValue);\r
- \r
- } // end if\r
- \r
- \r
- } // end setXmlData()\r
- \r
- /**\r
- * Print all values of the XML tag as a String\r
- */ \r
- public function toString()\r
- {\r
- $this->myXmlCollection->toString();\r
-\r
- \r
- }// toString() end \r
- \r
-} // end class XmlTagTrace\r
-?>
\ No newline at end of file