Class TXmlDocument

Description

TXmlDocument class.

TXmlDocument represents a DOM representation of an XML file. Besides all properties and methods inherited from TXmlElement, you can load an XML file or string by loadFromFile or loadFromString. You can also get the version and encoding of the XML document by the Version and Encoding properties.

To construct an XML string, you may do the following:

  1. $doc=new TXmlDocument('1.0','utf-8');
  2. $doc->TagName='Root';
  3.  
  4. $proc=new TXmlElement('Proc');
  5. $proc->setAttribute('Name','xxxx');
  6. $doc->Elements[]=$proc;
  7.  
  8. $query=new TXmlElement('Query');
  9. $query->setAttribute('ID','xxxx');
  10. $proc->Elements[]=$query;
  11.  
  12. $attr=new TXmlElement('Attr');
  13. $attr->setAttribute('Name','aaa');
  14. $attr->Value='1';
  15. $query->Elements[]=$attr;
  16.  
  17. $attr=new TXmlElement('Attr');
  18. $attr->setAttribute('Name','bbb');
  19. $attr->Value='1';
  20. $query->Elements[]=$attr;
The above code represents the following XML string:
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <Root>
  3. <Proc Name="xxxx">
  4. <Query ID="xxxx">
  5. <Attr Name="aaa">1</Attr>
  6. <Attr Name="bbb">1</Attr>
  7. </Query>
  8. </Proc>
  9. </Root>

  • since: 3.0
  • version: $Id: TXmlDocument.php 1398 2006-09-08 19:31:03Z xue $
  • author: Qiang Xue <qiang.xue@gmail.com>

Located in /Xml/TXmlDocument.php (line 273)

TComponent
   |
   --TXmlElement
      |
      --TXmlDocument
Method Summary
TXmlDocument __construct ([string $version = '1.0'], [string $encoding = ''])
string getEncoding ()
string getVersion ()
boolean loadFromFile (string $file)
boolean loadFromString (string $string)
void saveToFile (string $file)
string saveToString ()
void setEncoding (string $encoding)
void setVersion (string $version)
Methods
Constructor __construct (line 289)

Constructor.

  • access: public
TXmlDocument __construct ([string $version = '1.0'], [string $encoding = ''])
  • string $version: version of this XML document
  • string $encoding: encoding of this XML document

Redefinition of:
TXmlElement::__construct()
Constructor.
getEncoding (line 315)
  • return: encoding of this XML document
  • access: public
string getEncoding ()
getVersion (line 299)
  • return: version of this XML document
  • access: public
string getVersion ()
loadFromFile (line 334)

Loads and parses an XML document.

  • return: whether the XML file is parsed successfully
  • access: public
  • throws: TIOException if the file fails to be opened.
boolean loadFromFile (string $file)
  • string $file: the XML file path
loadFromString (line 348)

Loads and parses an XML string.

The version and encoding will be determined based on the parsing result.

  • return: whether the XML string is parsed successfully
  • access: public
boolean loadFromString (string $string)
  • string $string: the XML string
saveToFile (line 381)

Saves this XML document as an XML file.

  • access: public
  • throws: TIOException if the file cannot be written
void saveToFile (string $file)
  • string $file: the name of the file to be stored with XML output
saveToString (line 396)

Saves this XML document as an XML string

  • return: the XML string of this XML document
  • access: public
string saveToString ()
setEncoding (line 323)
  • access: public
void setEncoding (string $encoding)
  • string $encoding: encoding of this XML document
setVersion (line 307)
  • access: public
void setVersion (string $version)
  • string $version: version of this XML document

Inherited Methods

Inherited From TXmlElement

TXmlElement::__construct()
TXmlElement::getAttribute()
TXmlElement::getAttributes()
TXmlElement::getElementByTagName()
TXmlElement::getElements()
TXmlElement::getElementsByTagName()
TXmlElement::getHasAttribute()
TXmlElement::getHasElement()
TXmlElement::getParent()
TXmlElement::getTagName()
TXmlElement::getValue()
TXmlElement::setAttribute()
TXmlElement::setParent()
TXmlElement::setTagName()
TXmlElement::setValue()
TXmlElement::toString()

Inherited From TComponent

TComponent::addParsedObject()
TComponent::attachEventHandler()
TComponent::canGetProperty()
TComponent::canSetProperty()
TComponent::createdOnTemplate()
TComponent::detachEventHandler()
TComponent::evaluateExpression()
TComponent::evaluateStatements()
TComponent::getEventHandlers()
TComponent::getSubProperty()
TComponent::hasEvent()
TComponent::hasEventHandler()
TComponent::hasProperty()
TComponent::raiseEvent()
TComponent::setSubProperty()
TComponent::__get()
TComponent::__set()

Documentation generated on Sun, 14 Jan 2007 21:45:14 -0500 by phpDocumentor 1.3.0RC4