Packages:
default
System
System.Caching
System.Collections
System.Data
System.Data.ActiveRecord
System.Data.ActiveRecord.Relations
System.Data.ActiveRecord.Scaffold
System.Data.ActiveReecord.Scaffold.InputBuilder
System.Data.Commom.Sqlite
System.Data.Common
System.Data.Common.Mssql
System.Data.Common.Mysql
System.Data.Common.Oracle
System.Data.Common.Pgsql
System.Data.Common.Sqlite
System.Data.DataGateway
System.Data.SqlMap
System.Data.SqlMap.Configuration
System.Data.SqlMap.Statements
System.Exceptions
System.I18N
System.IO
System.Security
System.Util
System.Web
System.Web.Services
System.Web.UI
System.Web.UI.ActiveControls
System.Web.UI.WebControls
System.Web.UI.WebControls.assets
System.Xml


Classes:
Keyword

Class TXmlDocument

TComponent
   |
   --TXmlElement
      |
      --TXmlDocument

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
Author: Qiang Xue <qiang.xue@gmail.com>

Constructor Summary
public
__construct Array
Constructor.

Method Summary
string
string
boolean
loadFromFile ( string $file)
Loads and parses an XML document.
boolean
loadFromString ( string $string)
Loads and parses an XML string.
void
saveToFile ( string $file)
Saves this XML document as an XML file.
string
Saves this XML document as an XML string
void
setEncoding ( string $encoding)
void
setVersion ( string $version)
string
Magic-method override. Called whenever this document is used as a string.
Methods Inherited From TXmlElement
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()
Methods 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()

Constructor Details

__construct

public __construct Array

Constructor.


Method Details

getEncoding

public string getEncoding ()

Output
string encoding of this XML document
Exception

getVersion

public string getVersion ()

Output
string version of this XML document
Exception

loadFromFile

public boolean loadFromFile (string $file )

Loads and parses an XML document.

Input
string$filethe XML file path
Output
boolean whether the XML file is parsed successfully
Exception
throwsTIOException if the file fails to be opened.

loadFromString

public boolean loadFromString (string $string )

Loads and parses an XML string.

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

Input
string$stringthe XML string
Output
boolean whether the XML string is parsed successfully
Exception

saveToFile

public void saveToFile (string $file )

Saves this XML document as an XML file.

Input
string$filethe name of the file to be stored with XML output
Output
Exception
throwsTIOException if the file cannot be written

saveToString

public string saveToString ()

Saves this XML document as an XML string

Output
string the XML string of this XML document
Exception

setEncoding

public void setEncoding (string $encoding )

Input
string$encodingencoding of this XML document
Output
Exception

setVersion

public void setVersion (string $version )

Input
string$versionversion of this XML document
Output
Exception

__toString

public string __toString ()

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

  1. $document = new TXmlDocument();
  2. $document->TagName = 'root';
  3. echo $document;
or
  1. $document = new TXmlDocument();
  2. $document->TagName = 'root';
  3. $xml = (string)$document;

Output
string string representation of this document
Exception