Here's the workaround to assign data from XML tag into array!
| From: | Scott Fletcher | Date: | Mon, 05 Aug 2002 14:54:56 +0000 |
| Subject: | Here's the workaround to assign data from XML tag into array! | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-111210@lists.php.net to get a copy of this message | ||
Hi!
After a few days, I came to the conclusion that the workaround to the
PHP code for parsing XML and stuff like that are not going to work. Due to
the fact that the data have to be put into a file which is illegal for me to
store the credit bureau inquiry data. Again, due to the fact that that
parsing is only to tell if the XML tag is not broken or anything. Mozilla
browser can tell you that. So, here is what I did to make it happen, plain
and simple!!!!!!!!!!!!!!!!!!!!!!!!! It involved logic!!!!!
The variable, $res_str contain the XML stuff as a response in a serial
stream from the credit bureau. Let's say you want to get the data from the
XML tag and put it into an array out of bunch of XML tags,
"<CompletionCode>23scs3</CompletionCode>";
--clip--
//// the XML data into the PHP -----------------------------
$str_len = strlen($res_str);
$count = 0;
$BEGIN_COMPLETIONCODE = "";
$END_COMPLETIONCODE = "";
//// prevent infinite loop if the appropriate response is not received
if (substr($res_str,0,2) == "<?")
while($count < $str_len){
//// check for "<CompletionCode>" and "</CompletionCode>"
and put
it into PHP array
if (substr($res_str,$count,16) == "<CompletionCode>"){
$BEGIN_COMPLETIONCODE = ($count+16);
}
if (substr($res_str,$count,17) == "</CompletionCode>"){
$END_COMPLETIONCODE = ($count-$BEGIN_COMPLETIONCODE);
}
$count++;
}
}
$XML['CompletionCode'] =
substr($res_str,$BEGIN_COMPLETIONCODE,$END_COMPLETIONCODE);
echo substr($res_str,$BEGIN_COMPLETIONCODE,$END_COMPLETIONCODE)."<br>";
--clip--
Voila!! You got one data!!! If you have tons of XML tags with only some of
them come at a random while some other won't show up then you have got a
problem!!! We're gonna need PHP developer to write a function for that for
the sake of PHP people!!