File($filename, $fileOpenMode); $this->tag = new Tag(); $this->tag->tagStartOpen = "tag->tagClose = "?>"; if($this->connected && ($this->fileOpenMode == $this->fileOpenModeRead || $this->fileOpenMode == $this->fileOpenModeReadWrite)) { $fileContents = $this->getContents(); $this->close(); $this->parseFromString($fileContents); } else { $this->setDefaultXMLTag(); $this->xml = new XML(); } return $success; } /** * Returns the XML object containing actual XML tree; in PHP 4 make sure to use =& to get a reference instead of a copy * @method getXML * @returns object of type XML containing actual XML tree */ function getXML() { return $this->xml; } /** * Returns the XML string of a complete XML document * @method getXMLString * @returns string containing contents of XML document */ function getXMLString() { $xmlString = $this->tag->getTagString(); $xmlString .= "\n\n"; $xmlString .= $this->xml->getXMLString(0); return $xmlString; } /** * Parses XML document from supplied string, also called from constructor when parsing file contents * @method parseFromString * @param string XMLDocString * @returns none */ function parseFromString($XMLDocString) { $tagPos = $this->tag->setTagFromString($XMLDocString); if($tagPos === false) { $tagPos = array(0 => 0, 1 => 0); $this->setDefaultXMLTag(); } $xmlContents = trim(substr($XMLDocString, $tagPos[1])); $this->xml = new XML($xmlContents); } /** * Saves document contents to a supplied filename * @method save * @param string filename * @returns true if successful, false otherwise */ function save($filename) { $success = $this->open($filename, $this->fileOpenModeWrite); if($success) { $bytesWritten = $this->write($this->getXMLString()); if($bytesWritten <= 0) $success = false; $this->close(); } return $success; } /** * (Re)sets XML version/encoding to default values * @method setDefaultXMLTag * @returns none */ function setDefaultXMLTag() { $this->tag->setTagName("xml"); $this->tag->setAttribute("version", "1.0"); $this->tag->setAttribute("encoding", "UTF-8"); } /** * Sets encoding of the XML document * @method setEncoding * @param string encoding * @returns none */ function setEncoding($encoding) { $this->tag->setAttribute("encoding", $encoding); } /** * Sets version of the XML document * @method setVersion * @param string version * @returns none */ function setVersion($version) { $this->tag->setAttribute("version", $version); } /** * Sets XML object of the XMLDocument, sets/changes/updates XML content to the supplied XML tree, uses reference no copy is created * @method setXML * @param object xml * @returns true if successful, false otherwise */ function setXML(&$xml) { $success = false; if(gettype($xml) == "object" && strtolower(get_class($xml)) == "xml") { $this->xml = &$xml; $success = true; } return $success; } }