Unable to output XML data in a manageable way

Posted by Rob on Stack Overflow See other posts from Stack Overflow or by Rob
Published on 2013-11-11T09:19:27Z Indexed on 2013/11/11 9:54 UTC
Read the original article Hit count: 239

Filed under:
|

I've been given data from a previous version of a website (it was a custom CMS) and am looking to get it into a state that I can import it into my Wordpress site.

This is what I'm working on - http://www.teamworksdesign.com/clients/ciw/datatest/index.php. If you scroll down to row 187 the data starts to fail (there should be a red message) with the following error message:

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/teamwork/public_html/clients/ciw/datatest/index.php:132 Stack trace: #0 /home/teamwork/public_html/clients/ciw/datatest/index.php(132): SimpleXMLElement->__construct('

Can anyone see what the problem is and how to fix it?

This is how I'm outputting the date:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>

<?php


ini_set('memory_limit','1024M');

ini_set('max_execution_time', 500); //300 seconds = 5 minutes

echo "<br />memory_limit: " .  ini_get('memory_limit') . "<br /><br />";
echo "<br />max_execution_time: " .  ini_get('max_execution_time') . "<br /><br />";

libxml_use_internal_errors(true); 

$z = new XMLReader;
$z->open('dbo_Content.xml');

$doc = new DOMDocument;
$doc->preserveWhiteSpace = false;

// move to the first <product /> node
while ($z->read() && $z->name !== 'dbo_Content');

$c = 0;

// now that we're at the right depth, hop to the next <product/> until the end of the tree
while ($z->name === 'dbo_Content')
{

    if($c < 201) {

        // either one should work
        $node = simplexml_import_dom($doc->importNode($z->expand(), true));

        if($node->ClassId == 'policydocument') {

            $c++;

            echo "<h1>Row: $c</h1>";

            echo "<pre>";

            echo htmlentities($node->XML) . "<br /><br /><br /><b>*******</b><br /><br /><br />";

            echo "</pre>";

            try{ 
                $xmlObject = new SimpleXMLElement($node->XML);

                foreach ($xmlObject->fields[0]->field as $field) {

                    switch((string) $field['name']) {
                        case 'parentId':
                            echo "<b>PARENT ID: </b> " . $field->value . "<br />";
                            break;
                        case 'title':
                            echo "<b>TITLE: </b> " . $field->value . "<br />";
                            break;
                        case 'summary':
                            echo "<b>SUMMARY: </b> " . $field->value . "<br />";
                            break;
                        case 'body':
                            echo "<b>BODY:</b> " . $field->value . "<br />";
                            break;
                        case 'published':
                             echo "<b>PUBLISHED:</b> " . $field->value . "<br />";
                             break;
                    }
                }

                echo '<br /><h2 style="color:green;">Success on node: '.$node->ContentId.'</h2><hr /><br />';           

            } catch (Exception $e){ 
                echo '<h2 style="color:red;">Failed on node: '.$node->ContentId.'</h2>'; 
            }

        }

        // go to next <product />
        $z->next('dbo_Content');

    }


} ?>

</body>
</html>

© Stack Overflow or respective owner

Related posts about php

Related posts about Xml