Index |
Quick Docs |
Usage Examples
phpdomxml-0.9.0 Quick Docs
This project is my tiny contribution to the open source community. phpdomxml is an OOP implementation
of the XML DOM for
PHP. It tries not
to be a 100% complete implementation of the nifty w3c standards.
In fact, its aim is to be a light-weight implementation for 'every-day' usage of XML-documents in a PHP 4.10+ environment.
phpdomxml does not rely on any external libraries, it does however require the expat XML parser functions for PHP, which should be included by default.
The methods and properties follow the design as layed out by the World Wide
Web Consorticum and as was implemented in ECMAScript or compatible languages
like Javascript and Actionscript. phpdomxml does not support validating by
DTD through the document type definition. The document type is recorded when
reading an XML document, but not used.
Implementation
This project started out as a necassity for an OOP implementation
of the XML DOM for
PHP.
A few months ago PHP 5.0 was released and, though I didn't find the time to look under the hood,
it seems to have a very solid implementation of the DOM. Since it will take some time for hosting providers to
make the switch from PHP 4.x to PHP 5.0, it seemed like a good idea to release this work to the open source community.
There are some beautiful implementations of the XML DOM for PHP out there. I, however, took
the liberty of making some shortcuts by treating some of the objects as simple (associative)
PHP arrays. For instance, the Attr and NamedNodeMap interfaces are dropped and the attributes of an element can be
addressed by using the attributes array of an XML_Node interface, or by using the
DOM-compliant XML_Element::getAttribute().
The following interfaces are not implemented in phpdomxml: Attr,
DocumentFragment, DocumentType, DOMImplementation, Entity, EntityReference, NamedNodeMap,
NodeList, Notation and ProcessingInstruction.
Interfaces
The list below specifies interfaces and their methods and properties.
Elements denoted in red are w3c standards that are implemented in phpdomxml-0.9.0.
Elements denoted in are extensions to the standard.
- XML_CDATASection (spec)
Inherits the XML_CharacterData interface through the XML_Text interface.
- XML_CharacterData (spec)
The XML_CharacterData interface extends XML_Node with a set of
attributes and methods for accessing character data in the DOM.
Properties
Methods
- appendData (example) (spec)
Append the string to the end of the character data of the node.
- deleteData (example) (spec)
Deletes specified data.
- insertData (example) (spec)
Insert a string at the specified offset.
- replaceData (example) (spec)
Replace the characters starting at the specified offset with the specified string.
- substringData (example) (spec)
Extracts a range of data from the node.
- XML_Comment (spec)
From this object are accessible comments in XML,
i.e. all characters between "<!--" and "-->".
Extends XML_CharacterData.
- XML_Document (spec)
The Document interface represents the entire XML document. Conceptually, it is the root
of the document tree, and provides the primary access to the document's data.
Extends XML_Node.
Properties
- docType
- documentElement
- implementation
Methods
- createAttribute
- createAttributeNS
- createCDATASection (spec)
Creates a CDATASection node whose value is the specified string.
- createComment (example) (spec)
Creates a Comment node given the specified string.
- createDocumentFragment
- createElement (example) (spec)
Creates an element of the type specified. Note that the instance returned implements
the Element interface, so attributes can be specified directly on the returned object.
- createElementNS
- createEntityReference
- createProcessingInstruction
- createTextNode (example) (spec)
Creates a Text node given the specified string.
- getElementById (example) (spec)
Returns the Element whose ID is given by elementId. If no such element exists, returns null.
- getElementsByTagName (example) (spec)
Returns an array containing all Elements of the given name in the same order as they appear
in the source document.
- getElementsByTagNameNS
- importNode
- XML_Element (spec)
Apart from text, XML_Element nodes are the most common objects in every XML document.
Extends XML_Node.
Properties
- tagName
The name of the element.
Methods
- getAttribute (spec)
Retrieves an attribute value by name.
- getAttributeNode
- getAttributeNodeNS
- getAttributeNS
Return element with specified attribute 'id' set or null if none found.
- getElementsByTagName (spec)
Returns an array containing all Elements with the given tag name in the
same order as they appear in the source document.
- getElementsByTagNameNS
- hasAttribute (spec)
Returns true when an attribute with a given name is specified on this element, false otherwise.
- hasAttributeNS
- removeAttribute (spec)
Removes an attribute by name.
- removeAttributeNode
- removeAttributeNS
- setAttribute (example) (spec)
Adds a new attribute, or changes an existing one.
- setAttributeNode
- setAttributeNodeNS
- setAttributeNS
- XML_Node (spec)
The Node interface is the primary datatype for the entire Document Object Model.
It represents a single node in the document tree.
Properties
- attributes
An array containing the attributes of this node (if it is an Element)
or null otherwise.
- childNodes
An array that contains all children of this node.
- firstChild (example)
The first child of this node. If there is no such node, this returns null.
- lastChild (example)
The last child of this node. If there is no such node, this returns null.
- localName
- namespaceURI
- nextSibling (example)
The node immediately following this node. If there is no such node, this returns null.
- nodeName (example)
The name of this node.
- nodeType
A code representing the type of the underlying object
- XML_ELEMENT_NODE = 1
- XML_TEXT_NODE = 3
- XML_CDATA_SECTION_NODE = 4
- XML_COMMENT_NODE = 8
- XML_DOCUMENT_NODE = 9
- nodeValue (example)
The value of this node.
- ownerDocument
The Document object associated with this node. This is also the Document object
used to create new nodes.
- parentNode
The parent of this node. All nodes, except XML_Document may have a parent.
However, if a node has just been created and not yet added to the tree, or if it has been removed
from the tree, this is null.
- prefix
- previousSibling (example)
The node immediately preceding this node. If there is no such node, this returns null.
Methods
- appendChild (example) (spec)
Adds a new child to the end of the list of children of this node.
If the new child is already in the tree, it is first removed.
- cloneNode *
- hasAttributes (spec)
Returns whether this node (if it is an element) has any attributes.
- hasChildNodes (spec)
Returns whether this node has any children.
- insertBefore (spec)
Inserts a new child before an existing child node (refChild). If refChild is null, the new child
is added at the end of the list of children.
- isSupported
- normalize
- removeChild (example) (spec)
Removes the indicated child node from the list of children, and returns it.
- replaceChild *
- XML_Text (spec)
The XML_Text interface inherits from XML_CharacterData and represents the textual
content (termed character data in XML) of an Element.
Methods
The XML object inherits from XML_Document and serves as access point for
your XML needs in projects..
Methods
Load an XML document from the specified URL.
Save an XML document to the specified file or URL.
Parses the XML text in the specified argument.
Encodes the specified XML object into an XML document and sends
it to the specified URL using the POST method.
Encodes the specified XML object into an XML document, sends it to a specified
URL using the POST method, downloads the server's response and then loads it into a given target object.
The XML_Parser parses an XML document into a DOM object.
Methods
Parse a raw XML document.
License
Licensed under the GNU General Public License (GPL).
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
© 2005 webtweakers.com,
Bas van Gaalen, 14 April 2005. valid xhtml