## 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:

     $doc=new TXmlDocument('1.0','utf-8');
     $doc->TagName='Root';

     $proc=new TXmlElement('Proc');
     $proc->setAttribute('Name','xxxx');
     $doc->Elements[]=$proc;

     $query=new TXmlElement('Query');
     $query->setAttribute('ID','xxxx');
     $proc->Elements[]=$query;

     $attr=new TXmlElement('Attr');
     $attr->setAttribute('Name','aaa');
     $attr->Value='1';
     $query->Elements[]=$attr;

     $attr=new TXmlElement('Attr');
     $attr->setAttribute('Name','bbb');
     $attr->Value='1';
     $query->Elements[]=$attr;

The above code represents the following XML string:

     <?xml version="1.0" encoding="utf-8"?>
     <Root>
       <Proc Name="xxxx">
         <Query ID="xxxx">
           <Attr Name="aaa">1</Attr>
           <Attr Name="bbb">1</Attr>
         </Query>
       </Proc>
     </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