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>';
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.
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:
> 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:
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:
> On 30 Jun., 21:16, rwhite35 <rwh...@echotimesoftware.com> wrote:
> > 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:
> 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:
> > 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:
> > > 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:
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:
> 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:
> > 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:
> > > 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:
> > > > 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