Jump to content

Parsing an XML document that contains &


brohrbach

Recommended Posts

I'm trying to parse an XML document that contains an & in the data. When php parses the & it breaks the line into 3 lines instead of one.

Here's the PHP code:
function opening_element($parser, $element, $attributes){
global $flag1;
if ($element == "image"){
$flag1 = "image";
}
}
function closing_element($parser, $element){
global $flag1;
if ($element == "image"){
$flag1 = "";
}
}
function character_data($parser, $data){
global $flag1;
if ($flag1 == "image"){
global $images1;
$images1[] = $data;
}
}

$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");

$document = file("exp1.xml");
foreach ($document as $line) {
xml_parse($parser, $line);
}
xml_parser_free($parser);


Here's the XML:
<image>img/exp/03/B-Architecture &amp; nature...jpg</image>

Here's the result:
img/exp/03/B-Architecture
&
nature...jpg

It breaks it into 3 lines when I want it in one line.

Any suggestions?
Edit/Delete Message
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.