I have some XML being returned to me which has the following entity within it:
<offer-url>
[url]http://stat.someurl.com/DealFrame/DealFrame.cmp?BEFID=96339&code=813&aon=[/url]^&crawl
er_id=306826&dealId=a9T6vnaKtX18Rs1CnHjUBw%3D%3D&prjID=ds&url=http%3A%2F%2Fwww.m
odchipstore.com%2Fcustomer%2Fproduct.php%3Fproductid%3D16162&DealName=Brand%20NEW%2
1%20Pre-Modified%20Microsoft%20Xbox%20Console&MerchantID=306826
&category=8&MT=&DB=masterprod&MN=&HasLink=yes&frameId=-1&AR=1&RR=1&NG=&GR=1
&ND=1&FPT=DSP&NDS=&NMS=&NDP=&MRS=&CT=6&linkin_id=3059680&DMT=1&VK=3059687
&searchID=c34ee49a43592c2905ce02d4&PD=20246920</offer-url>
(note, line breaks added to make this thread readable)
When I parse it using the standard xml parser, all I get back is PD=20246920
I thought it was because of the naked & so I did a:
$line = str_replace('&', '& amp;', $line);
However, now all I get back is amp;PD=20246920
Any ideas what I'm missing here? I bet I'll have egg on my face once I figure it out, but I've been staring at this on and off for a couple of days and haven't found it. My xml parsing routines are relatively simple:
function opening_element($parser, $element, $attributes) {
global $section, $name, $id;
if ( $section ) {
$name = $element;
}
switch($element) {
case "phrase":
$section = $element;
break;
case "category":
$section = $element;
break;
case "image":
$section = $element;
break;
case "domain":
$section = $element;
break;
case "store-offer";
$section = $element;
list ( $key, $value ) = each ( $attributes );
$id = $value;
break;
}
}
function closing_element($parser, $element) {
global $section, $id;
switch($element) {
case "phrase":
$section = '';
break;
case "category":
$section = '';
break;
case "image":
$section = '';
break;
case "domain":
$section = '';
break;
case "store-offer":
$section = '';
$id = '';
break;
}
}
function character_data($parser, $data) {
global $section, $phrase, $category, $domain, $offers,
$image, $name, $id;
switch($section) {
case "phrase":
$phrase[$name] = $data;
break;
case "category":
$category[$name] = $data;
break;
case "image":
$image = $data;
break;
case "domain":
$domain[$name] = $data;
break;
case "store-offer";
$offers[$id][$name] = $data;
break;
}
}
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
xml_set_element_handler($parser, 'opening_element', 'closing_element');
xml_set_character_data_handler($parser, 'character_data');
which does what I need it to do in terms of setting up the data into structures that I can use.
Thanks for any help.