PRADO Component Framework for PHP 5
  • Home
  • About
  • Testimonials
  • Demos
  • Download
  • Documentation
  • Forum
  • Development
  • Tutorials
  • Class Docs
  • API Manual
  • Wiki

Packages

  • None
  • System
    • Caching
    • Collections
    • Data
      • ActiveRecord
        • Relations
        • Scaffold
          • InputBuilder
      • Commom
        • Sqlite
      • Common
        • Mssql
        • Mysql
        • Oracle
        • Pgsql
        • Sqlite
      • DataGateway
      • SqlMap
        • Configuration
        • Statements
    • Exceptions
    • I18N
    • IO
    • Security
    • Util
    • Web
      • Javascripts
      • Services
      • UI
        • ActiveControls
        • WebControls
    • Xml
  • Wsat
    • pages
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo

Class 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 TXmlDocument::loadFromFile() or TXmlDocument::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>
TComponent
Extended by TXmlElement
Extended by TXmlDocument
Package: System\Xml
Copyright: Copyright © 2005-2014 PradoSoft
License: http://www.pradosoft.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 3.0
Located at Xml/TXmlDocument.php
Methods summary
public
# __construct( string $version = '1.0', string $encoding = '' )

Constructor.

Constructor.

Parameters

$version
string
version of this XML document
$encoding
string
encoding of this XML document

Overrides

TXmlElement::__construct()
public string
# getVersion( )

Returns

string
version of this XML document
public
# setVersion( string $version )

Parameters

$version
string
version of this XML document
public string
# getEncoding( )

Returns

string
encoding of this XML document
public
# setEncoding( string $encoding )

Parameters

$encoding
string
encoding of this XML document
public boolean
# loadFromFile( string $file )

Loads and parses an XML document.

Loads and parses an XML document.

Parameters

$file
string
the XML file path

Returns

boolean
whether the XML file is parsed successfully

Throws

TIOException
if the file fails to be opened.
public boolean
# loadFromString( string $string )

Loads and parses an XML string. The version and encoding will be determined based on the parsing result.

Loads and parses an XML string. The version and encoding will be determined based on the parsing result.

Parameters

$string
string
the XML string

Returns

boolean
whether the XML string is parsed successfully
public
# saveToFile( string $file )

Saves this XML document as an XML file.

Saves this XML document as an XML file.

Parameters

$file
string
the name of the file to be stored with XML output

Throws

TIOException
if the file cannot be written
public string
# saveToString( )

Saves this XML document as an XML string

Saves this XML document as an XML string

Returns

string
the XML string of this XML document
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;

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;

Returns

string
string representation of this document

Overrides

TXmlElement::__toString()
protected TXmlElement
# buildElement( DOMXmlNode $node )

Recursively converts DOM XML nodes into TXmlElement

Recursively converts DOM XML nodes into TXmlElement

Parameters

$node
DOMXmlNode
the node to be converted

Returns

TXmlElement
the converted TXmlElement
Methods inherited from TXmlElement
getAttribute(), getAttributes(), getElementByTagName(), getElements(), getElementsByTagName(), getHasAttribute(), getHasElement(), getParent(), getTagName(), getValue(), setAttribute(), setParent(), setTagName(), setValue(), toString()
Methods inherited from TComponent
__call(), __destruct(), __get(), __isset(), __set(), __sleep(), __unset(), __wakeup(), addParsedObject(), asa(), attachBehavior(), attachBehaviors(), attachClassBehavior(), attachEventHandler(), canGetProperty(), canSetProperty(), clearBehaviors(), createdOnTemplate(), detachBehavior(), detachBehaviors(), detachClassBehavior(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), evaluateStatements(), fxAttachClassBehavior(), fxDetachClassBehavior(), getAutoGlobalListen(), getBehaviorsEnabled(), getClassHierarchy(), getEventHandlers(), getListeningToGlobalEvents(), getSubProperty(), hasEvent(), hasEventHandler(), hasProperty(), isa(), listen(), raiseEvent(), setSubProperty(), unlisten()
Constants inherited from TComponent
GLOBAL_RAISE_EVENT_LISTENER
Terms of Service | Contact Us
PRADO v3.2.4 API Manual API documentation generated by ApiGen 2.8.0
Copyright © 2006-2014 by the PRADO Group.
Powered by PRADO