- Home
- About
- Testimonials
- Demos
- Download
- Documentation
- Blogs
- Forum
- Support

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: TXmlDocument TXmlElement TXmlElementList |
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:

     $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 Author: Qiang Xue <qiang.xue@gmail.com>
Constructor Summary
public | __construct Array Constructor.
Method Summary
string | getEncoding ()
string | getVersion ()
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 | saveToString () Saves this XML document as an XML string
void | setEncoding ( string $encoding)
void | setVersion ( string $version)
string | __toString () 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 | $file | the XML file path
Output
boolean | whether the XML file is parsed successfully
Exception
throws | TIOException 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 | $string | the 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 | $file | the name of the file to be stored with XML output
Output
Exception
throws | TIOException 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 | $encoding | encoding of this XML document
Output
Exception
## setVersion
public void setVersion | (string $version )
Input
string | $version | version of this XML document
Output
Exception
## __toString
public string __toString | ()
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;
Output
string | string representation of this document
Exception