dylanburkey
4/24/2014 - 3:08 PM

SimpleXml

SimpleXml

<?php
###########################################################################
# This loads the amended XML document to display the prices of the books. #
# The code that displays the prices is on line 46.                        #
###########################################################################
$xml = simplexml_load_file('inventory2.xml');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Using SimpleXML</title>
<link href="simplexml.css" rel="stylesheet" type="text/css" />

    <style>
        .main {
            margin: 1em 0;
            float: left;
            border-top: thick solid #222;
        }
    </style>
</head>

<body>
<?php
$page_id = (int) $_GET['page_id'];

if($page_id = NULL){
    $page_id = '1';
if ($xml->page[1]->asXML('page2.xml')) {
    echo 'XML saved';
}
}


if($page_id = '2'){
   if($xml->page[2]->asXML){

   }
}

foreach ($xml->page as $page) {
    print_r('<div class="main">');

    echo '<h2>' . $page->title . '</h2>';

    print_r('<h3>' . $page->name . '</h3>');

   print_r('<h3><a href="' . $page->url . '">' . $page->url .' </a></h3>');


    # Show SEO VARS

    print_r('<strong> <u>SEO Vars</u> <br> Canonical URL: ' . $page->seo->cannonical .  '</strong>');
    print_r('<br> <i>Description: </i>' . $page->seo->desc . '<br>');
    print_r('<br> <i>keywords: </i>' . $page->seo->keywords . '<br>');


    foreach($page->contents->content as $content ){
        if($page->contents->content->displayTitle = 0){
            print '1';
        }
     print_r('<h4>' . $content->title . '</h4>');
     print_r('<h4>' . $content->pcontent . '</h4>');
    }



    foreach($page->seo as $seo){
        echo $seo->desc;
        echo $seo->keywords;
    }

    print_r('</div>');
}


?>
</body>
</html>