Class c_xml

  • Make XML

    $item['book']['title']='Little Prince';
    $item['book']['@author']='Antoine Marie Jean-Baptiste Roger de Saint-Exupéry';
    $o_xml=new c_xml();
    $o_xml->fromArray('books', $item);
  • Load XML

    from file
    $o_xml=new c_xml($xml);
    from string
    $xml='<item pos="10"><title>c_xml</title><link>/my_classes/c_xml</link></item>';
    $o_xml=new c_xml($xml);
  • Convert XML to Array

    Array (
      [*] => books
      [.] => 
      [book] => Array (
        [*] => book
        [.] => 
        [@author] => Antoine Marie Jean-Baptiste Roger de Saint-Exupéry
        [title] => Array (
          [*] => title
          [.] => Little Prince
  • Show XML-dump

    echo c_xml::dump( $o_xml->toXML() );
  • XSL-transformation

    echo c_xml::transform($xsl_file, $xml, $params);
    <xsl:template match="data">
      <xsl:for-each select="bike">
        <xsl:value-of select="@model"/> (<xsl:value-of select="@year"/>) - <xsl:value-of select="owner"/><br/>
      <bike model="giant" year="2011"><owner>Koreyko</owner></bike>
      <bike model="turist" year="2011"><owner>Ostap</owner></bike>
      <bike model="trak" year="2011"><owner>Kisa</owner></bike>
    giant (2011) - Koreyko<br>
    turist (2011) - Ostap<br>
    trak (2011) - Kisa<br>


This class can convert between XML files and arrays or strings.

It can parse a XML file into a DOM document object, so it can be returned as an array or displayed using a XSL stylesheet.

The parsed XML document can also be manipulated to add, change or remove nodes. Nodes may be searched using XPath.

The resulting document can be regenerated in XML format.

Page on phpClasses.