## 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 2771 2010-02-16 14:55:38Z Christophe.Boulain $
- author: Qiang Xue <qiang.xue@gmail.com>

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

    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)
string __toString ()
Methods
Constructor __construct (line 323)

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 349)

- return: encoding of this XML document
- access: public

string getEncoding ()
getVersion (line 333)

- return: version of this XML document
- access: public

string getVersion ()
loadFromFile (line 368)

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 382)

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 434)

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 449)

Saves this XML document as an XML string

- return: the XML string of this XML document
- access: public

string saveToString ()
setEncoding (line 357)

- access: public

void setEncoding (string $encoding)

- string $encoding: encoding of this XML document

setVersion (line 341)

- access: public

void setVersion (string $version)

- string $version: version of this XML document

__toString (line 471)

Magic-method override. Called whenever this document is used as a string.

     $document = new TXmlDocument();
     $document->TagName = 'root';
     echo $document;

or

     $document = new TXmlDocument();
     $document->TagName = 'root';
     $xml = (string)$document;

- return: string representation of this document
- access: public

string __toString ()

Redefinition of:

TXmlElement::__toString()
  Magic-method override. Called whenever this element is used as a string.

#### 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()
> 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 Mon, 22 Feb 2010 12:19:06 +0000 by phpDocumentor 1.3.0RC4