PXML

PXML is standard XML used to describe components of the pexeso framework. It is called PXML and has extension .pxml to distinguish it from other XML files. Possibility to describe the application in XML is the most essential feature of the pexeso framework as it greatly simplifies the application design.

XML was natural choice as it is standard, well-understood among developers, the parsers and writer exists and it is of course extensible. Additionaly it allows schema creation where advanced editting application can take advantage of it and supply content assits when writing PXML and validation preventing most of syntactical mistakes to be left unnoticed.

The PXML is in pexeso unmarshalled to object structure using several standard rules:

  • Each element (except special PXML constructs) represents PHP class or component instance. Name of the element is mapped to the PHP class or component name.
  • Attributes defined for element represents properties and the values assigned to them for object represented by the element they are defined on.
  • Child elements represents children of the object represented by the parent element. When children are unmarshalled they are assigned to the parent object like items of the array on they respective indices in order in which they are specified in PXML. The object representing parent element must implement ArrayAccess interface.
  • Element px:assign is special PXML construct as it does not represents any class or component instance. It provides another way of assigning property of the object value. Contents of the px:assign after it is umarshalled is assigned to property specified by property attribute of the object represented by parent element.
Example:
<?xml version="1.0" encoding="UTF-8"?>
<px:Component xmlns:h="http://www.w3.org/1999/xhtml"
	xmlns:px="http://pexeso-php.sourceforge.net/1.0"
	title="Example">
	
	<px:assign property="controller">
		<ExampleController/>
	</px:assign>
	
	<h:h3>Example</h:h3>
	
	<h:p>This is an example of the simple component.</h:p>
</px:Component>

This example represents instance of the px:Component that has assigned title property to "Example" string and controller property to instance of the ExampleController. It also has a two children - first is instance of the h:h3 and has itself one string child, the second is instance of h:p and also has one string child.

Namespaces

Namespaces can be used to map XML elements to specific PHP classes and when associated with schema they can be also used to validate contents of the XML file. By deafult the PXML component resolver can understand components/classes from two namespaces:

  • http://www.w3.org/1999/xhtml - which is standard XHTML namespace
  • http://pexeso-php.sourceforge.net/1.0 - namespace of all PX components/classes

Unresolved components/classes are looked up in the same way as as PHP files included using include language construct - the look up starts in current script's folder and continues in folder specified by PHP's include_path property.

It is also possible to define namespace by PHP package that can be usefull when your project has more adavnced structure and you are using PHP namespaces.

The following example represents component/class that has fully qualified PHP name my\component\namespace\MyAdvancedComponent.

<my:MyAdvancedComponent xmlns:my="my\component\namespace"/>

Element identifier

Each element in the PXML file can have attribute name specified. It does not represent a property of the class represented by the element but rather unique identifier of the object in the PXML definition. See Component for details.