Jump to content


Photo

parsing xml cdata


  • Please log in to reply
3 replies to this topic

#1 Drumminxx

Drumminxx
  • Members
  • PipPipPip
  • Advanced Member
  • 92 posts
  • LocationUSA

Posted 15 July 2006 - 10:45 PM

Why do I get these strange characters after parsing some xml

this is what an xml item looks like:

<blurb><![CDATA[ATTIK Leeds creates key art for flagship game – BLACK.]]></blurb>

now the dash you see above "game - BLACK"

comes back like this

ATTIK Leeds creates key art for flagship game – BLACK.

I found success using str_replace but is there a built-in function I could be using?
I couldn't find it if there is...

:: gucci.com ::
:: blockbuster.com ::

--------------------

#2 Branden Wagner

Branden Wagner
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts

Posted 16 July 2006 - 04:14 AM

what are you using to parse the xml?

#3 OOP

OOP
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts
  • LocationSaudi Arabia

Posted 16 July 2006 - 04:19 AM

check the characters set you are using in your XML document
<?php echo'The man who makes no mistakes does not usually make anything'; ?>

#4 Drumminxx

Drumminxx
  • Members
  • PipPipPip
  • Advanced Member
  • 92 posts
  • LocationUSA

Posted 16 July 2006 - 04:54 AM

I'm thinking that these are some mac characters, them New Yorkers always got to be different and can't just use a PC, but then I don't know much about mac's anyway so I could be wrong.

<?xml version="1.0" encoding="UTF-8"?>

heres how I'm parsing the xml minus the start, end and data functions
	$xml_parser = xml_parser_create();
	xml_parser_set_option($xml_parser,XML_OPTION_SKIP_WHITE,false);//this could probably go but...

	xml_set_element_handler($xml_parser, "client_startTag", "client_endTag");
	xml_set_character_data_handler($xml_parser, "client_tagData");
	$file = '../en-us/xml/'.$sub_cat_id[$i][3];
	$data = xml_parse($xml_parser,file_get_contents($file));
	xml_parser_free($xml_parser);
	
	if(!$data) {
	   die(sprintf("XML error: %s at line %d",
	xml_error_string(xml_get_error_code($xml_parser)),
	xml_get_current_line_number($xml_parser)));


now I've tried several encode, decode functions php offers I just can't seem to find one that works right.
here are some functions that I'm using that works just so you can see what kind of characters i'm dealing with

function fixchars($text)	{
	$bad = array('’','–','‘');
	$good = array('&rsquo;','&ndash;','&rsquo;');
	$text = str_replace($bad, $good, $text);
	return $text;
}

function bfixchars($text)	{
	$bad = array('’','–','‘');
	$good = array('’','-','’');
	$text = str_replace($bad, $good, $text);
	return $text;
}


:: gucci.com ::
:: blockbuster.com ::

--------------------




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users