|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-10-03 13:44 UTC] keyboard27 dot 10 at gmail dot com
Description:
------------
"Warning: main() [function.main]: Cannot add element <XML-element-name> number 1 when only 0 such elements exist"
I get this error when trying to read from an xml-file.
In the file i need to jump to a parent-element from a child-element.
//Code:
if((int)$Verse_ID >= sizeof($Chap->Verse))
{
if((int)$Chap_ID >= sizeof($Book[($Book_ID-1)]))
{
if((int)$Book_ID == sizeof($xml_Books->Book))
{
$Book_ID = 1;
$Chap_ID = 1;
$Verse_ID = 1;
}
else
{
$Book_ID++;
$Chap_ID = 1;
$Verse_ID = 1;
}
}
else
{
$Chap_ID++;
$Verse_ID = 1;
}
}
else
{
$Verse_ID++;
}
//$Chap, $xml_Books and $Book are xml-nodes
Test script:
---------------
//Code:
if((int)$Verse_ID >= sizeof($Chap->Verse))
{
if((int)$Chap_ID >= sizeof($Book[($Book_ID-1)]))
{
if((int)$Book_ID == sizeof($xml_Books->Book))
{
$Book_ID = 1;
$Chap_ID = 1;
$Verse_ID = 1;
}
else
{
$Book_ID++;
$Chap_ID = 1;
$Verse_ID = 1;
}
}
else
{
$Chap_ID++;
$Verse_ID = 1;
}
}
else
{
$Verse_ID++;
}
//$Chap, $xml_Books and $Book are xml-nodes
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 20:00:01 2025 UTC |
<?php //$Verse_ID = 22 (retrieved from database) //$Chap_ID = 1 (retrieved from database) //$Book_ID = 2 (retrieved from database) //$Chap = XML Node //$Chap->Verse = xml node array(size: 22) //$Book = xml node array(size: 66) //$book[($book_id-1)] = xml node array(size: 40) //$xml_books = xml node //$xml_books->book = xml node array(size:66) if((int)$Verse_ID >= sizeof($Chap->Verse)) { if((int)$Chap_ID >= sizeof($Book[($Book_ID-1)])) { if((int)$Book_ID == sizeof($xml_Books->Book)) { $Book_ID = 1; $Chap_ID = 1; $Verse_ID = 1; } else { $Book_ID++; $Chap_ID = 1; $Verse_ID = 1; } } else { $Chap_ID++; $Verse_ID = 1; } } else { $Verse_ID++; } ?>