EZ XML

Author Message

Mike Cohen

Wednesday 22 January 2003 1:08:48 pm

Does anyone know how to use eZ XML to load information from an XML file into an eZ Publish template? The SDK examples show the use of eZ XML in a php file, but I don't think php will work in a .tpl file. I tried to use the SDK example in template, but it doesn't seem to work. Here's what I put in a class edit template, both with and without the {literal} tags.

{literal}
<?php
include_once( "/lib/ezxml/classes/ezxml.php" );

$xml = new eZXML();
$testDoc = "<?xml version='1.0'?>
<doc>
<article>
<paragraph name='Introduction'>Paragraph contents</paragraph>
<paragraph name='Story'>Story paragraph contents</paragraph>
</article>
</doc>";

$dom =& $xml->domTree( $testDoc );

print( "<b>XML document to parse:</b><br>" );

print( nl2br( htmlspecialchars( $testDoc ) ) );

print( "<br><b>Results from parsing:</b><br>" );
$paragraphs =& $dom->elementsByName( "paragraph" );

foreach ( $paragraphs as $paragraph )
{
// get the name of the item, should be paragraph
print( "<br/>New " . $paragraph->name() . ":<br/>" );

// print the value of the name attribute
print( "Name: " . $paragraph->attributeValue( "name" ) . "<br/>" );
print( "Content: " . $paragraph->textContent() . "<br/>" );
}

?>
{/literal}

Thanks for any help,

Mike