PDA

View Full Version : Simple XML load file


moos3
10-09-2007, 02:02 AM
How can I check for a simple xml object is loaded? heres what I have so far?

if(empty($_GET['t'])){
$tab = 'overview';
}
elseif(empty($_GET['t']) && !empty($_GET['p'])){
echo "You Can't have a Panel with out a Tab!";
$run = false;
}
else{
$h = $_GET['t'];
$tab = base64_decode($_GET['t']);
if(empty($_GET['p'])){
$cPanel = 1;
$nCnext = $cPanel+1;
$nCprev = (int)$cPanel-1;
}
else{
$cPanel = (int)$_GET['p'];
$nCnext = (int)$cPanel+1;
$nCprev = (int)$cPanel-1;
}
//Load XML for panels based of url
$xml = @simplexml_load_file('panels/'.$tab.'.xml');
if(empty($xml)){
$run = false;
$set = true;
}
else{
$totPanel = 0;
foreach($xml->pane as $panel){
$totPanel++;
}
$predicate = "//num[.='{$cPanel}']/ancestor::pane";
$pane1 = current($xml->xpath($predicate));
}
}

moos3
10-09-2007, 02:17 AM
to show where its the true and false are used..

if($run == true){
foreach($pane1->formLoad as $form){
echo '<form method="'.$form->formMethod.'" action="'.$form->formAction.'">';
foreach($form->ffield as $fields){
echo '<label for="'.$fields->name.'">'.$fields->name.'</label><input type="'.$fields->type.'" id="'.$fields->id.'" name="'.$fields->name.'"';
if($fields->onKeyUp == true){
echo 'onKeyUp="'.$fields->onKeyUp.'" />';
echo '<br />';
}
else{
echo ' />';
echo '<br />';
}
}
echo '<input type="hidden" name="'.$xml->pane->name.'" value="'.$cPanel.'" ><input type="submit" name="Save" />';
echo '</form>';
}
}
else{
if($set == false){
echo 'No Pane To Display. Make sure you have click on a tab.';
}
else{
echo 'No Panes to Load';
}
}

moos3
10-09-2007, 04:15 AM
bump, Any takers?

kbluhm
10-09-2007, 05:06 AM
If I'm understanding you correctly, you could use an exception with try/catch syntax:
<?php

try
{
$xml = simplexml_load_file( 'panels/' . $tab . '.xml' );
$run = TRUE;
}
catch ( Exception $error )
{
$run = FALSE;
}

?>

Inigoesdr
10-09-2007, 05:18 AM
bump, Any takers?

You don't set $run to true anywhere. Also you should be able to check whether or not the xml file loads with empty(), like you do already, or is_object().

moos3
10-09-2007, 05:27 AM
cool thanks the try works prefectly.