VFXP - Very Fast XML Parser
- Author: Claudio Castelpietra
- Email: claudio@wopweb.com
- Web site: http://www.wopweb.com/
- License: "LGPL"
- Release history:
- 18/11/2005 - v.1.0 - First release.
- 24/01/2006 - v.1.1 - Some API added. Some php compatibility issues fixed.
- 23/05/2015 - v.1.2 - Added some XPATH methods: setValueXP and getNodeXP.
-
Description:
- Very Fast XML Parser for PHP.
- Completely standalone: no need for any PHP extension library.
- Very fast processing, using iterative single-cycle parsing, instead of recursive or multi-step parsing.
- Very useful for just loading simple application configuration parameters.
- Strongly simplified and intuitive DOM API, with respect to the DOM Core Level 1
- Works with PHP >= 3
- Limitations in version 1.0:
- XML version and encoding declaration tags are ignored.
- DOCTYPE declaration tags are ignored.
- Notes:
- I developed this class because the faster extension-independent free PHP XML parser I've found took about 500 milliseconds to parse my configuration file, and this is not acceptable for a web page generation.
- This class takes about 20 times less than the previous one.
- Anyway, this it a PHP-interpreted class, so its performance cannot be compared to a C-compiled class.
API Reference
// The Document Class
//
class VFXP_Document {
// Parses XML from a file
//
void parseFromFile(string $filename);
// Parses XML from a string
//
void parseFromString(string $content);
// Returns a reference to the root Element
//
VFXP_Element & rootElement();
}
// The Document Element
//
class VFXP_Element {
// Returns the name of the element
//
string name();
// Returns the value of the element
//
string value();
// Returns true if there is at least one child with the given name
//
bool hasChildren(string $elementname = NULL);
// Returns a reference to the first element with the given name, or NULL if not found.
//
VFXP_Element & firstChild(string $elementname = NULL);
// Returns the value of the first child with the given name, or NULL if not found.
//
string childValue(string $elementname = NULL);
// Returns an array of references to the subelements having a given name.
//
array children(string $elementname = NULL);
// Returns an associative array of couples (child-name => child-value)
//
array childrenAssociative();
// Returns a reference to the array-map of the attribute-name=>attribute-value pairs
//
array & attributes();
// Returns the value of the given attribute, or NULL if not found
//
string attributeValue(string $attributename);
/**
* Sets the value of a child node, creating it if it's missing,
* using a simil-xpath syntax
* Supported xpath syntax:
* subelementname[/subsubelementname]*
*/
setValueXP(string $path, string $value);
/**
* Searches for a single node, using a simil xpath syntax:
* Supported xpath syntax examples:
* element[2]/subelement[subsubelement=value]
*/
EpstXpElement getNodeXP(string $path);
}