Skip to end of metadata
Go to start of metadata

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[

Zend Framework: Zend_Xml Component Proposal

Proposed Component Name Zend_Xml
Developer Notes
Proposers Daniele Orlando
Revision 0.1 - 1 August 2006: Initial Release (wiki revision: 9)

Table of Contents

1. Overview

Zend_Xml is a component that allow you to read nodes, create roots, append childs, set attributes, create texts in a XML resource, simply passing an XPath string or an array of strings with few or no parameters.
For instance, recursive operation on different xml node can be done passing an array of xpath strings.
In the same way, passing an xpath string and an array of node name strings, we can add many childs in just one function call.
This is possible combining the simplicity of the XPath syntax with the DOM versatility.
Simply useful.

2. References

3. Component Requirements, Constraints, and Acceptance Criteria

Zend_Xml is a low level library for XML Document creation and manipulation.

  • This component will not supports conversion in other markup languages or document types.
  • This component must supports all PHP DOM methods.

4. Dependencies on Other Framework Components

  • Zend_Exception

5. Theory of Operation

Instantiate Zend_Xml with the root name(s) of the xml document and, if required, the external stylesheet.
Now, you are ready to build your XML document quickly and with total control on every operation.

6. Milestones / Tasks

  • Milestone 1: [DONE] Base operations support
  • Milestone 2: Full support for PHP DOM methods
  • Milestone 3: Support for pre-existent DOMDocument and SimpleXML objects
  • Milestone 4: Performance tuning

7. Class Index

  • Zend_Xml - xml creation and manipulation class
  • Zend_Xml_Exception - exception handler

8. Use Cases


Creation of a new XML document with an external stylesheet:


Basic editing:


Recursive operations:

9. Class Skeletons

The complete class is in "Attachments"



xml xml Delete
xpath xpath Delete
dom dom Delete
zend_xml zend_xml Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Apr 05, 2007

    <p>it seems useful, keep working on it, i'll try the class. Anyone else is...? </p>

  2. Jun 05, 2007

    <p>What does this proposed class do that DOMDocument doesn't do already?</p>

    <p>There is no need to reinvent functionality that already exists by another name in standard PHP.</p>

    1. Jun 09, 2007

      <p>Hi, Bill!<br />
      I think that DOMDocument is a powerful and complete component, too.<br />
      But this is not a valid reason to consider Zend_Xml useless.<br />
      Their scope is the same, but the way to achieve it is different.<br />
      It's up to the developer to decide how to do it.<br />
      So, I can answer that I'm not reinventing functionality, but I'm proposing a simpler and faster way to use them.</p>

      <p>Why simpler and faster?</p>
      <ac:macro ac:name="code"><ac:plain-text-body><![CDATA[

      /* Example 1 */

      // DOMDocument way
      $xml = new DOMDocument('1.0', 'UTF-8') ;
      $xml->appendChild(new DOMProcessingInstruction('xml-stylesheet', 'type="text/xsl" encoding="UTF-8" href="http://www.domain.dom/xsl/stylesheet.xsl"' ) ;
      $xml->appendChild(new DOMElement('Service')) ;

      // Zend_Xml way
      $xml = new Zend_Xml('Service', 'http://www.domain.dom/xsl/stylesheet.xsl', 'UTF-8', '1.0') ;

      /* Example 2 */

      // DOMDocument way
      $xpath = new DOMXPath($xml) ;
      $paths = array('//user[@level="high"]', '//admin') ;
      foreach ($paths as $path) {
      $nodelist = $xpath->query($path) ;
      foreach ($nodelist as $node)

      Unknown macro: { $sub = $node->appendChild(new DOMDocument('name')) ; $sub->nodeValue = 'nick' ; $sub->setAttribute('active','1') ; }


      // Zend_Xml way
      $xml->appendChild(array('//user[@level="high"]','//admin'), array('name'=>'nick'),array('active'=>'1')) ;


      <p>Zend_Xml is not a replacement for DOMDocument, but a wrapper that let the developer to program without the rewriting of repetitive code but just using arrayes and xpath strings.<br />
      And wheter you have to use DOMDocument, simply use Zend_Xml->$Dom instance.<br />
      Is there anything simpler and faster than this?</p>

      <p>Thanks for your time.</p>

      <p>p.s.:<br />
      I'm using Zend_Xml in a production system and I think it very useful.</p>

  3. Sep 12, 2007

    <p>Updated...<br />
    Now supports namespaces.</p>

  4. Aug 28, 2008

    <p>Nevermind, just noted: <a class="external-link" href=""></a></p>