Jump to content

Recommended Posts

Hello, I'm in need of help. Sometimes my PHP reads XML from a ssh and it tends to fail at times.

 

Heres my complete error:

 

[04-Aug-2010 18:03:16] PHP Warning:  SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: Entity: line 3: parser error : Premature end of data in tag info line 2 in /home/nmdgamin/public_html/private/includes/functions/revision.php on line 69
[04-Aug-2010 18:03:16] PHP Warning:  SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]:  in /home/nmdgamin/public_html/private/includes/functions/revision.php on line 69
[04-Aug-2010 18:03:16] PHP Warning:  SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: ^ in /home/nmdgamin/public_html/private/includes/functions/revision.php on line 69
[04-Aug-2010 18:03:16] PHP Fatal error:  Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/nmdgamin/public_html/private/includes/functions/revision.php:69
Stack trace:
#0 /home/nmdgamin/public_html/private/includes/functions/revision.php(69): SimpleXMLElement->__construct('<?xml version="...')
#1 /home/nmdgamin/public_html/private/includes/functions/update.php(16): CheckRemoteRevision('SpaceBuild')
#2 /home/nmdgamin/public_html/prv_updater.php(13): Update()
#3 {main}
  thrown in /home/nmdgamin/public_html/private/includes/functions/revision.php on line 69

 

Remote function:

 

function CheckRemoteRevision($Name){
    if($Name){
        if($Query = MySQLQuery('SELECT name, url, sv_revision FROM data WHERE name=\''. $Name .'\';')){
            if($XMLFile = shell_exec('svn info \''. $Query['url'] .'\' --username anonsvn --password anonsvn --xml')){
                if($DCheck = explode(' ', $XMLFile)){
                    if($DCheck[0] == 'svn:'){
                        $Revision = '0';
                        $Result = MySQLQuery('UPDATE data SET sv_revision=\''. $Revision .'\' WHERE name=\''. $Query['name'] .'\';');
                        return False;
                    }
                }
                $XML = new SimpleXMLElement($XMLFile);
                foreach($XML->entry as $Attribute){
                    $Revision = $Attribute['revision']; 
                }
                if($Query['sv_revision'] < $Revision || $Query["sv_revision"] != $Revision){
                    $Result = MySQLQuery('UPDATE data SET sv_revision=\''. $Revision .'\' WHERE name=\''. $Query['name'] .'\';');
                }
                return $Revision;
            }else{
                return False;
            }
        }else{
            return False;
        }
    }else{
        return False;
    }
}

 

How would I full proof this from getting this error again, It seems to happen at completely random times.

 

I'm not very good with XML in PHP

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/209891-xml-simplexmlelement__construct-problem/
Share on other sites

I would personally use the simplexml_load_string() function to return a SimpleXMLElement Object.

Use the following to prevent your error.

<?php
libxml_use_internal_errors(true);
// xml contained in $xml
$xml = "";
if(!$simpleXML = simplexml_load_string($xml)) {
print "Badly formatted XML document";
}
else {
foreach($simpleXML->entry as $Attribute){

}
}
?>

I have included some of your code in my script:

 

function CheckRemoteRevision($Name){
    if($Name){
        if($Query = MySQLQuery('SELECT name, url, sv_revision FROM data WHERE name="'. $Name .'";')){
            if($XMLFile = shell_exec('svn info "'. $Query['url'] .'" --username anonsvn --password anonsvn --xml')){
                if($DCheck = explode(' ', $XMLFile)){
                    if($DCheck[0] == 'svn:'){
                        $Revision = '0';
                        $Result = MySQLQuery('UPDATE data SET sv_revision="'. $Revision .'" WHERE name="'. $Query['name'] .'";');
                        return False;
                    }
                }
                if($XML = simplexml_load_string($XMLFile)){
                    $XML = new SimpleXMLElement($XMLFile);
                    foreach($XML->entry as $Attribute){
                        $Revision = $Attribute['revision']; 
                    }
                    if($Query['sv_revision'] < $Revision || $Query["sv_revision"] != $Revision){
                        $Result = MySQLQuery('UPDATE data SET sv_revision="'. $Revision .'" WHERE name="'. $Query['name'] .'";');
                    }
                }else{
                    echo "[". CurTime() ."] Addon \"". $Name ."\" seemed to have suffered an XML error. Retrying...\n";
                    CheckRemoteRevision($Name);
                }
                return $Revision;
            }else{
                return False;
            }
        }else{
            return False;
        }
    }else{
        return False;
    }
}

 

I can't test it until it errors itself if it does.

 

Thanks for the help though. Hope that fixes my stupid problem! ;)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.