4 * This class provides the functionality to trace an xml tag
\r
9 private $tagToTrace; // the xml tag to be collected
\r
10 private $tagToTraceLevel; // The level of the xml tag bo be collected/traced
\r
11 private $xmlString; // Xml data as string
\r
13 private $xmlTag; // temporary object to store XML object while reading xml array
\r
14 private $xmlTagState; // true or false if tracing tag is done
\r
15 private $myXmlCollection; // collection of the traced xml tag
\r
18 * Class Constructor: starts tracing a XML tag. It recieves a xml TagName and xml TagLevel
\r
19 * @param String $theXmlString XML data as String
\r
20 * @param String $theTagToTrace XML Tag to trace
\r
21 * @param String $theTagToTraceLevel Level of the XML tag to trace
\r
23 function __construct($theXmlString,$theTagToTrace,$theTagToTraceLevel)
\r
27 //$this->xmlString = $theXmlString;
\r
29 // set the tag to trace and the starting level
\r
30 $this->tagToTrace = $theTagToTrace;
\r
31 $this->tagToTraceLevel = $theTagToTraceLevel;
\r
33 // create XML tag Collection
\r
34 $this->myXmlCollection = new XmlTagCollection();
\r
37 $this->traceXmlTag($theXmlString);
\r
38 } // __construct() end
\r
41 * Returns the XML tag Collection
\r
44 public function getCollection()
\r
46 //get from here of from XmlTagCollection collection object???
\r
47 return $this->myXmlCollection->getXmlTagCollection();
\r
48 //return $this->myXmlCollection;
\r
52 }// end getCollection()
\r
55 * Creates an XML parcer and Iterates through array
\r
57 * @param unknown_type $theXmlString
\r
59 private function traceXmlTag($theXmlString)
\r
61 // create XML parser
\r
62 $p = xml_parser_create();
\r
64 // parse XML data into array
\r
65 xml_parse_into_struct($p, $theXmlString, $xmlVals, $xmlIndex);
\r
68 xml_parser_free($p);
\r
70 // initialize XML object ????
\r
71 //$myXmlTag = new XmlTag()
\r
74 // start looping xml array
\r
75 for($i = 0; $i < count($xmlVals); $i++)
\r
77 // initialize XML data
\r
82 $theTagAtrib = Array();
\r
84 // verify data before adding
\r
85 if (isset($xmlVals[$i]['tag']))
\r
87 $theTagName = $xmlVals[$i]['tag'];
\r
90 if (isset($xmlVals[$i]['type']))
\r
92 $theTagType = $xmlVals[$i]['type'];
\r
95 if (isset($xmlVals[$i]['level']))
\r
97 $theTagLevel = $xmlVals[$i]['level'];
\r
100 if (isset($xmlVals[$i]['value']))
\r
102 $theTagValue = $xmlVals[$i]['value'];
\r
105 if (isset($xmlVals[$i]['attributes']))
\r
107 $theTagAtrib = $xmlVals[$i]['attributes'];
\r
111 $this->setXmlData($theTagName,$theTagType,$theTagLevel,$theTagValue,$theTagAtrib);
\r
114 } // end for loop xml array
\r
116 } // end traceXmlTag()
\r
119 * Recieves Xml data from each tag and determines if values should be collected
\r
120 * this to trace <P> and <div> tags
\r
122 * @param String $theTagName
\r
123 * @param String $theTagType
\r
124 * @param String $theTagLevel
\r
125 * @param String $theTagValue
\r
126 * @param String $theTagAtrib
\r
128 private function setXmlData($theTagName,$theTagType,$theTagLevel,$theTagValue,$theTagAtrib)
\r
131 //echo '<br/>'.$this->tagToTrace;
\r
133 // verify also if the level is lower !!!!
\r
135 //echo '<br/>'.$theTagName;
\r
136 // verify if this data is from the xml tag being traced/collected
\r
137 if ($theTagName == $this->tagToTrace)
\r
140 //echo '<br/>'.$theTagName.' TAG IS THE SAME';
\r
141 //echo '<br/>Value: '.$theTagValue.'';
\r
144 // if tag is complete. The tag has NO children
\r
145 if ($theTagType=='complete')
\r
147 // create a XmlTag object
\r
148 $this->xmlTag = new XmlTag($theTagName,$theTagType,$theTagLevel,$theTagValue,$theTagAtrib);
\r
150 // tracing this tag is done.
\r
151 $this->xmlTagState = true;
\r
153 $this->xmlTag->setTagState(true);
\r
155 //echo '<br/>'.$theTagName.' TAG is complete !!!';
\r
157 //$this->xmlTag->toString();
\r
159 // add to collection
\r
160 $this->myXmlCollection->addXmlTagObject($this->xmlTag);
\r
162 // reset temp object
\r
163 $this->xmlTag = null;
\r
165 } // end if complete
\r
167 // if tag is open. tag do have children
\r
168 else if ($theTagType=='open')
\r
170 // create a new XmlTag object
\r
171 $this->xmlTag = new XmlTag($theTagName,$theTagType,$theTagLevel,$theTagValue,$theTagAtrib);
\r
173 // tracing this tag is NOT done.
\r
174 $this->xmlTagState = false;
\r
176 //echo '<br/>'.$theTagName.' TAG is Open !!!';
\r
180 // if tag cdata. Getting data of the traced Tag, after any children data
\r
181 else if ($theTagType=='cdata')
\r
183 // add value to traced tag
\r
184 // OJO !! This skips any child value
\r
185 $this->xmlTag->addToTagValue($theTagValue);
\r
187 // tracing this tag is NOT done.
\r
188 $this->xmlTagState = false;
\r
189 //echo '<br/>'.$theTagName.' TAG is cdata!!!';
\r
194 // if tag close. Getting data of the traced Tag is done
\r
195 else if ($theTagType=='close')
\r
197 // add value of traced tag
\r
198 $this->xmlTag->addToTagValue($theTagValue);
\r
200 // tracing this tag is NOT done.
\r
201 $this->xmlTagState = true;
\r
203 $this->xmlTag->setTagState(true);
\r
204 //echo '<br/>'.$theTagName.' TAG is close!!!';
\r
206 //add to collection
\r
207 $this->myXmlCollection->addXmlTagObject($this->xmlTag);
\r
209 // reset temp object
\r
210 $this->xmlTag = null;
\r
215 }// end if tracing xml tag
\r
218 * if the tag is a children. the tagToTraceLevel is lower than the current TagLevel
\r
219 * this for all tags like <br/>, <b>, <i>, <u>, or even for <span> inside our traced tag
\r
221 if ($this->tagToTraceLevel<$theTagLevel && (isset($this->xmlTag)))
\r
223 // adding children data to tag as value
\r
224 $this->xmlTag->addChildTagAsValue($theTagName,$theTagType,$theTagValue);
\r
229 } // end setXmlData()
\r
232 * Print all values of the XML tag as a String
\r
234 public function toString()
\r
236 $this->myXmlCollection->toString();
\r
239 }// toString() end
\r
241 } // end class XmlTagTrace
\r