alohaaaron
Programmer
Hi, I'm able to parse out XML elements and get the values of the attributes but not the names. For example I get ContactPricing and Price and the values 20 and 28 but I can't get the "email" or "phone".
Code:
$parser=xml_parser_create();
$element_attrs = array();
function start($parser,$element_name,$element_attrs) {
global $element_attrs; //array of attributes
}
function stop($parser,$element_name) {
echo "<br />";
}
function characterData($parser,$data) {
global $element_attrs; //array of attributes
echo $data;
if (is_array($element_attrs)) {
while(list($key,$val) = each($element_attrs)) {
echo "<br>$key</br>"; //doesn't print out anything
echo "<br>$val</br>"; //doesn't print out anything
}
}
}
test data in xml file
<ContactPricing>
<Price contactType="email">20</Price>
<Price contactType="phone">28</Price>
</ContactPricing>