special char parsing in xml

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
henkha
Forum Newbie
Posts: 4
Joined: Wed Sep 19, 2007 11:06 pm

special char parsing in xml

Post by henkha »

I have a problem with the following

Code: Select all

$data = "<STRING> 
<ORIGINAL>Add New Page</ORIGINAL> 
<TRANSLATION>Neue Seite hinzufügen</TRANSLATION> 
<TRANSLATION>&#26032;&#12375;&#12356;&#12506;&#12540;&#12472;&#12434;&#36861;&#21152;</TRANSLATION> 
</STRING>";
if(!(xml_parse($xml_parser, $data, true))){
   die(error_base_xml(20000,"could not parse the xml structure","Error on line " . xml_get_current_line_number($xml_parser)));
}
the function will give a parser error
Does anyone know how to resolve this problem
The XML gets posted to the page though a windows application what is using msxl parser what has no problems with these special characters

Made a slight change to the message as for some reason there were " in the string

it fails on ü or the english pound key, japenees characters etc
Last edited by henkha on Thu Sep 20, 2007 8:16 pm, edited 2 times in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

A double-quoted string starts with the first " and ends with the next " (unless it's marked via \ )
Therefore php sees the string "<STRING>
<ORIGINAL>" followed by the unknown keyword Add -> syntax error.
try e.g.

Code: Select all

$data = <<< eox
<STRING>
<ORIGINAL>"Add New Page"</ORIGINAL>
<TRANSLATION>"Neue Seite hinzufügen"</TRANSLATION>
<TRANSLATION>"&#26032;&#12375;&#12356;&#12506;&#12540;&#12472;&#12434;&#36861;&#21152;"</TRANSLATION>
</STRING>
eox;
instead.
Post Reply