PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
toArray() not playing nicely with PHP-generaged XML document

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> Configuration
View previous topic :: View next topic  
Author Message
shamrog12



Joined: 06 Aug 2007
Posts: 7

PostPosted: Mon Aug 06, 2007 2:36 am    Post subject: toArray() not playing nicely with PHP-generaged XML document Reply with quote

First I should point out that I'm using Apache to handle .pxml documents as PHP....

Here's my concept: i'm using PHP to generate an XML file with dynamic content to be stored in the XML. Displaying the .pxml document in the browser shows correct, pretty XML with the dynamic data in the correct places.

... now for the Config object's role...

I'm simply trying to take this PHP-generated XML (.pxml extension) document and turn it into an array with Config's toArray() function. I'm doing it this way:

Code:

$this->xml_source = $_SERVER['DOCUMENT_ROOT']."/includes/config/pages.pxml";      

// read the XML document
$this->parsed_config = $this->obj_config->parseConfig($this->xml_source, 'XML');
// convert XML to array
$this->xml_as_array = $this->parsed_config->toArray();


This works great if I remove the dynamic aspect of the .pxml document or if I use a hardcoded XML file with some content.

Here's the .pxml file:

Code:

<?php
$test = "5555";
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
?>
<configuration>
   <page url="/services/index.php">
      <elements>
         <button>
            <button_href>/contact/?topic={$test}</button_href>
         </button>
      </elements>
   </page>
</configuration>
EOT;

header('Content-Type: application/xml');
header('Content-Disposition: inline; filename=pages.xml');
echo $xml;
?>


Viewing this in the browser shows:

Code:

<?xml version="1.0" encoding="ISO-8859-1"?>
<configuration>
   <page url="/services/index.php">
      <elements>
         <button>
            <button_href>/contact/?topic=5555</button_href>
         </button>
      </elements>
   </page>
</configuration>


The web page shows this error:

Fatal error: Call to undefined method XML_Parser_Error::toArray() in /home/public_html/class_xmlreader.php on line 41

Line 41 is $this->xml_as_array = $this->parsed_config->toArray();

Does toArray() read the straight text from the XML file rather than processing it and reading the output (which would be my dynamically generated XML in theory)?

Thanks.
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1230

PostPosted: Mon Aug 06, 2007 12:06 pm    Post subject: Reply with quote

This message
Quote:
Fatal error: Call to undefined method XML_Parser_Error::toArray() in /home/public_html/class_xmlreader.php on line 41

means that $this->parsed_config is an instance of XML_Parser_Error which extends PEAR_Error.

You need to check $this->parsed_config like this:
Code:

if (PEAR::isError($this->parsed_config)) {
    die($this->parsed_config->getMessage() . ', ' . $this->parsed_config->getDebugInfo());
}


die() is of course only reasonable for debugging, you need to do something more reasonable according to your error handling concept.
Back to top
View user's profile Send private message
shamrog12



Joined: 06 Aug 2007
Posts: 7

PostPosted: Tue Aug 07, 2007 2:03 am    Post subject: Reply with quote

mark wrote:
This message
Quote:
Fatal error: Call to undefined method XML_Parser_Error::toArray() in /home/public_html/class_xmlreader.php on line 41

means that $this->parsed_config is an instance of XML_Parser_Error which extends PEAR_Error.

You need to check $this->parsed_config like this:
Code:

if (PEAR::isError($this->parsed_config)) {
    die($this->parsed_config->getMessage() . ', ' . $this->parsed_config->getDebugInfo());
}


die() is of course only reasonable for debugging, you need to do something more reasonable according to your error handling concept.


excellent, learning more about the intricacies of PEAR every day. I added this line and I get:

XML_Parser: Empty document at XML input line 3:56,

as a result of:
Code:

$this->parsed_config = $this->obj_config->parseConfig($this->xml_source, 'XML');
if (PEAR::isError($this->parsed_config)) {
     die($this->parsed_config->getMessage() . ', ' . $this->parsed_config->getDebugInfo());
}
// convert XML to array
$this->xml_as_array = $this->parsed_config->toArray();


I'm not sure how to feel about the error because if you view the .pxml document in the browser it's definitely not empty.
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1230

PostPosted: Tue Aug 07, 2007 3:06 pm    Post subject: Reply with quote

To which class does the parseConfig() method belong? Does it accept filenames or only strings? (=> file_get_contents() would then be your friend.)
Back to top
View user's profile Send private message
shamrog12



Joined: 06 Aug 2007
Posts: 7

PostPosted: Wed Aug 08, 2007 6:48 am    Post subject: Reply with quote

This is the Config::parseConfig method i'm using.
Back to top
View user's profile Send private message
shamrog12



Joined: 06 Aug 2007
Posts: 7

PostPosted: Wed Aug 08, 2007 6:49 am    Post subject: Reply with quote

Additionally, it may be important to bring up again that the regular .xml file I have worked without issue. It's only my .pxml file which is my PHP dynamically-created XML file.
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1230

PostPosted: Wed Aug 08, 2007 8:54 am    Post subject: Reply with quote

Have you made sure that the path to the file is correct? Does
Code:
readfile($this->xml_source);
output your XML code? Do you have the usual error reporting activated?

Code:

error_reporting(E_ALL);
ini_set('display_errors', 1);
PEAR::setErrorHandling(PEAR_ERROR_DIE);
Back to top
View user's profile Send private message
shamrog12



Joined: 06 Aug 2007
Posts: 7

PostPosted: Wed Aug 08, 2007 8:30 pm    Post subject: Reply with quote

yes and yes.

If I remove the PHP code from the .pxml document then there is no issue and everything runs smoothly. As soon as I make the .pxml page have dynamic content by using PHP, it stops working. Examples of my PHP usage are in my first post.
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1230

PostPosted: Wed Aug 08, 2007 9:27 pm    Post subject: Reply with quote

shamrog12 wrote:
If I remove the PHP code from the .pxml document then there is no issue and everything runs smoothly. As soon as I make the .pxml page have dynamic content by using PHP, it stops working. Examples of my PHP usage are in my first post.


Then it might help to send the right content-type at the beginning of the .pxml script. (header('Content-type: ...'Wink
Back to top
View user's profile Send private message
shamrog12



Joined: 06 Aug 2007
Posts: 7

PostPosted: Fri Aug 10, 2007 6:56 am    Post subject: Reply with quote

mark wrote:
shamrog12 wrote:
If I remove the PHP code from the .pxml document then there is no issue and everything runs smoothly. As soon as I make the .pxml page have dynamic content by using PHP, it stops working. Examples of my PHP usage are in my first post.


Then it might help to send the right content-type at the beginning of the .pxml script. (header('Content-type: ...'Wink


This is what I am showing in my code from the first post. Is this wrong or something?

Code:

header('Content-Type: application/xml');
header('Content-Disposition: inline; filename=pages.xml');
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1230

PostPosted: Fri Aug 10, 2007 7:10 am    Post subject: Reply with quote

shamrog12 wrote:
This is what I am showing in my code from the first post. Is this wrong or something?[...]


No, I just didn't remember that you already did that ...
Back to top
View user's profile Send private message
shamrog12



Joined: 06 Aug 2007
Posts: 7

PostPosted: Mon Aug 13, 2007 6:06 pm    Post subject: Reply with quote

Sorry for not keeping up with the thread. Gmail thinks this is spam all the time so it's a challenge.

So, do we know what XML_Parser: Empty document at XML input line 3:56, might be implying? If you're a PEAR guru I wonder if this is something you could attempt to duplicate locally? That would be a huge help.

I'm basically trying to parse an XML file with extension .pxml that has some PHP at the top (you could use my code from the first post) using toArray(). The PHP at the top seems to have something to do with the error since if I were to remove the PHP and make the root XML tag be the first piece of data in the code, the error doesn't occur.
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1230

PostPosted: Tue Aug 14, 2007 3:19 pm    Post subject: Reply with quote

shamrog12 wrote:
So, do we know what XML_Parser: Empty document at XML input line 3:56, might be implying? If you're a PEAR guru I wonder if this is something you could attempt to duplicate locally? That would be a huge help.


I'm not a guru (I didn't chose that avatar, BTW, it was placed by the forum admin there).

There are too many things missing to easily reproduce your problem, and there are also many possible reasons for the error. I can only give you some hints.

The first debugging step would be to do a "echo file_get_contents(...);" with the path/URL to the .pxml file. Does that output look right?

If no, you'll know what you need to fix. If yes, you could place similar calls into the parser code and see how the XML code looks there.
Back to top
View user's profile Send private message
primeminister
Site Admin


Joined: 16 Apr 2006
Posts: 95
Location: Netherlands

PostPosted: Wed Aug 15, 2007 2:22 pm    Post subject: Reply with quote

Ha Mark,

Indeed the Avatar is chosen by me, actually because you so many posts it automatically adds that avatar to your name. Just let me know if you want to remove this.

Oh and BTW.... Thanks for so much contribution to the PEAR forum! Really many thanks!
Back to top
View user's profile Send private message Send e-mail
mark



Joined: 07 Jan 2007
Posts: 1230

PostPosted: Wed Aug 15, 2007 7:09 pm    Post subject: Reply with quote

ministry wrote:
Ha Mark,

Indeed the Avatar is chosen by me, actually because you so many posts it automatically adds that avatar to your name. Just let me know if you want to remove this.

Oh and BTW.... Thanks for so much contribution to the PEAR forum! Really many thanks!


I'll send you a private message about this ...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> Configuration All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement