Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
SimpleXMLIterator returning empty nodes
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
rwhite35  
View profile  
 More options Jun 29, 5:56 pm
From: rwhite35 <rwh...@echotimesoftware.com>
Date: Mon, 29 Jun 2009 14:56:20 -0700 (PDT)
Local: Mon, Jun 29 2009 5:56 pm
Subject: SimpleXMLIterator returning empty nodes
Hi All,

Anybody have experience with SimpleXMLIterator, specifically, this
function returns an object from an XML string that is created when I
use APIlity downloadXmlReport function.  The process IS returning the
data I need plus several empty rows, which I think are the column
labels (there seems to be correlation between the empties and the
number of children node before the target child).

I've tried xpath and that didn't seem to work also tried to put the
result in to another array, however since this creates an object, the
process exits with an error.

Here my code:

//get all the reports
$handle = array(getAllJobs());
//set the report id
$reportID = $handle[0][0]['id'];

(...)

if (!$handle){
        echo "<p>No Report to Download</p>";
        exit(2);

}

else{
//create xml string
$xmlReport = downloadXmlReport($reportID);
try {
//create a new simpleXMLIterator object
$sxi =new SimpleXMLIterator($xmlReport);
echo '<ul class="nav">';
//iterate through xml string
foreach ( $sxi as $node )
{
        foreach ($node as $k=>$v){
//iterate through the node rows
for ($i=0; $i<count($v); $i++)
echo '<li>'.$v->row[$i]["Query"].'</li>';
}
}
echo "</ul>";
}

catch(Exception $e)
{
echo $e->getMessage();

}
}

As always any help is most appreciated
rwhite35

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jan  
View profile  
 More options Jun 30, 6:03 am
From: Jan <piotrow...@gmail.com>
Date: Tue, 30 Jun 2009 03:03:51 -0700 (PDT)
Local: Tues, Jun 30 2009 6:03 am
Subject: Re: SimpleXMLIterator returning empty nodes
What are you trying to do?
print_r of the object would help.

- Jan


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
rwhite35  
View profile  
 More options Jun 30, 9:16 am
From: rwhite35 <rwh...@echotimesoftware.com>
Date: Tue, 30 Jun 2009 06:16:27 -0700 (PDT)
Local: Tues, Jun 30 2009 9:16 am
Subject: Re: SimpleXMLIterator returning empty nodes
Hi Jan,

Thanks for the reply.  I'm providing my users two sets of data, the
Search Queries and Keywords with clicks.  The above generates the data
I want but with four or five empty rows. The only row that should
return in the report are 1.) "Query" and 2.) only rows with valid
content.  In doing more research on the subject and SimpleXmlItorator
may not be the right tool due to the complex structure of the object
it creates.  Any case, I'm still in need of a solution and here is the
print_r for the sxi object which is created from the above.

Thanks in advance!

SimpleXMLIterator Object
(
    [table] => SimpleXMLIterator Object
        (
            [columns] => SimpleXMLIterator Object
                (
                    [column] => Array
                        (
                            [0] => SimpleXMLIterator Object
                                (
                                    [@attributes] => Array
                                        (
                                            [name] => campaign
                                        )

                                )

                            [1] => SimpleXMLIterator Object
                                (
                                    [@attributes] => Array
                                        (
                                            [name] => Query
                                        )

                                )

                            [2] => SimpleXMLIterator Object
                                (
                                    [@attributes] => Array
                                        (
                                            [name] => clicks
                                        )

                                )

                            [3] => SimpleXMLIterator Object
                                (
                                    [@attributes] => Array
                                        (
                                            [name] => pos
                                        )

                                )

                        )

                )

            [rows] => SimpleXMLIterator Object
                (
                    [row] => Array
                        (
                            [0] => SimpleXMLIterator Object
                                (
                                    [@attributes] => Array
                                        (
                                            [campaign] => October-
Design Ad
                                            [Query] => brochure design
                                            [clicks] => 1
                                            [pos] => 13.0
                                        )

                                )

                            [1] => SimpleXMLIterator Object
                                (
                                    [@attributes] => Array
                                        (
                                            [campaign] => October-
Design Ad
                                            [Query] => graphic design
                                            [clicks] => 1
                                            [pos] => 1.0
                                        )

                                )

                            [2] => SimpleXMLIterator Object
                                (
                                    [@attributes] => Array
                                        (
                                            [campaign] => October-
Design Ad
                                            [Query] => graphic design
studio
                                            [clicks] => 1
                                            [pos] => 4.0
                                        )

                                )

                            [3] => SimpleXMLIterator Object
                                (
                                    [@attributes] => Array
                                        (
                                            [campaign] => October-
Design Ad
                                            [Query] => graphic designs
                                            [clicks] => 1
                                            [pos] => 11.0
                                        )

                                )

                            [4] => SimpleXMLIterator Object
                                (
                                    [@attributes] => Array
                                        (
                                            [campaign] => October-
Design Ad
                                            [Query] => how to sell my
basketball cards online
                                            [clicks] => 1
                                            [pos] => 3.0
                                        )

                                )

                            [5] => SimpleXMLIterator Object
                                (
                                    [@attributes] => Array
                                        (
                                            [campaign] => October-
Design Ad
                                            [Query] => jobs
                                            [clicks] => 1
                                            [pos] => 1.0
                                        )

                                )

                            [6] => SimpleXMLIterator Object
                                (
                                    [@attributes] => Array
                                        (
                                            [campaign] => October-
Design Ad
                                            [Query] => logo or design
upload brochure printing
                                            [clicks] => 1
                                            [pos] => 9.0
                                        )

                                )

                            [7] => SimpleXMLIterator Object
                                (
                                    [@attributes] => Array
                                        (
                                            [campaign] => October-
Design Ad
                                            [Query] => october design
                                            [clicks] => 1
                                            [pos] => 1.0
                                        )

                                )

                            [8] => SimpleXMLIterator Object
                                (
                                    [@attributes] => Array
                                        (
                                            [campaign] => October-
Design Ad
                                            [Query] => pittsburgh
advertising agencies
                                            [clicks] => 1
                                            [pos] => 16.0
                                        )

                                )

                            [9] => SimpleXMLIterator Object
                                (
                                    [@attributes] => Array
                                        (
                                            [campaign] => October-
Design Ad
                                            [Query] => website design
                                            [clicks] => 1
                                            [pos] => 4.5
                                        )

                                )

                        )

                )

        )

    [totals] => SimpleXMLIterator Object
        (
            [grandtotal] => SimpleXMLIterator Object
                (
                    [@attributes] => Array
                        (
                            [clicks] => 10
                            [pos] => 8.0909090909
                        )

                )

        )

)

On Jun 30, 10:03 am, Jan <piotrow...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jan  
View profile  
 More options Jun 30, 10:15 am
From: Jan <piotrow...@gmail.com>
Date: Tue, 30 Jun 2009 07:15:30 -0700 (PDT)
Local: Tues, Jun 30 2009 10:15 am
Subject: Re: SimpleXMLIterator returning empty nodes
Do you know how to get the 'row' array?

- Jan


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
rwhite35  
View profile  
 More options Jun 30, 3:16 pm
From: rwhite35 <rwh...@echotimesoftware.com>
Date: Tue, 30 Jun 2009 12:16:26 -0700 (PDT)
Local: Tues, Jun 30 2009 3:16 pm
Subject: Re: SimpleXMLIterator returning empty nodes
Hey Jan,
If you mean can I pull the array "row" out of the object "sxi" and
then operate on the array by itself, no, I don't think so, not right
off the top.  But I can research that as an option.

I did try and put all of the sxi object in to an array, but that
failed with errors like, invalid array or object.

The above script is pulling the data out of the object as expected,
but with the extra empties. Here is what the output looks like

*
*
*
*
brochure design
graphic design
graphic design studio
graphic designs
how to sell my basketball cards online
jobs
logo or design upload brochure printing
october design
pittsburgh advertising agencies
website design

//end

rwhite35

On Jun 30, 2:15 pm, Jan <piotrow...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jan  
View profile  
 More options Jul 1, 3:50 am
From: Jan <piotrow...@gmail.com>
Date: Wed, 1 Jul 2009 00:50:59 -0700 (PDT)
Local: Wed, Jul 1 2009 3:50 am
Subject: Re: SimpleXMLIterator returning empty nodes
Then just skip the first 4.

$i = 0;

before the loop,

if($i < 4) {
echo...

}

$i++;

in the loop. Quick and dirty, but works.

- Jan

On 30 Jun., 21:16, rwhite35 <rwh...@echotimesoftware.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
rwhite35  
View profile  
 More options Jul 1, 11:37 am
From: rwhite35 <rwh...@echotimesoftware.com>
Date: Wed, 1 Jul 2009 08:37:20 -0700 (PDT)
Local: Wed, Jul 1 2009 11:37 am
Subject: Re: SimpleXMLIterator returning empty nodes
Thanks Jan,

I gave it a try, however it drops the first four rows of the Query
node too.  So the output becomes:

how to sell my basketball cards online
jobs
logo or design upload brochure printing
etc...

I was able to visualize the node tree using a different SPL and it
looks like this by nodal name:

table
- columns
- - column   //these are the four empties being output
- rows
- - row    //these are the ten valid being output
- totals
- grandtotals

If xpath worked, it would like something like: 'table/rows/row'
Where row is an array with a numeric key and an associative element
(or node) named "Query".  I've tried iterating over the
SimpleXmlIterator using LimitIterator, but that failed as well.
Unfortunately all the examples I can find are of simple XML strings
without numerous children to contend with.

rwhite35

On Jul 1, 7:50 am, Jan <piotrow...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jan  
View profile  
 More options Jul 1, 12:39 pm
From: Jan <piotrow...@gmail.com>
Date: Wed, 1 Jul 2009 09:39:44 -0700 (PDT)
Local: Wed, Jul 1 2009 12:39 pm
Subject: Re: SimpleXMLIterator returning empty nodes
Then use the $i-thingy on the outer foreach-loop and only output the
second run (skip first one).

- Jan

On 1 Jul., 17:37, rwhite35 <rwh...@echotimesoftware.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
rwhite35  
View profile  
 More options Jul 1, 9:57 pm
From: rwhite35 <rwh...@echotimesoftware.com>
Date: Wed, 1 Jul 2009 18:57:38 -0700 (PDT)
Local: Wed, Jul 1 2009 9:57 pm
Subject: Re: SimpleXMLIterator returning empty nodes
Jan, the Loop Guru!
Your suggestion did it (with a minor adjustment).  For the sake of
completeness, I'm posting the final solution.  Ultimately, there had
to be two conditional statements, one for the outer foreach, as you
said, and one for the inner foreach.  Here is the final code which
works as expected.

<?PHP

if (!$handle){
        echo "<p>No Report to Download</p>";
        exit(2);

}

else{
//create xml string
$xmlReport = downloadXmlReport($reportID);
//a new simpleXMLIterator object
try {
$sxi = new SimpleXMLIterator($xmlReport);
echo '<ul class="nav">';
//iterate through the outer loop
//skip the first node(0) by setting $e to 1
$e=1;
        foreach ($sxi as $node){
       if ($e<=count($node)){
        foreach ($node as $k => $v){
        }
        $e++;
}
}

//now iterate again through the inner loop
        for ($i=0; $i<count($v); $i++){
        echo '<li>'.$v->row[$i]["Query"].'</li>';
        }
echo "</ul>";
}

catch(Exception $e)
{
echo $e->getMessage();
}
}

?>

This outputs one the object array "Query" and nothing else.  HUGE
thanks for all your thoughts.  I appreciate the effort.
rwhite35

On Jul 1, 4:39 pm, Jan <piotrow...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google