Re: [PHP] Parsing entities in XML attributes

2004-06-24 Thread Decapode Azur
Hi,

The problem I had has not exactly the same, but quite close,
it was to make a pure xml template system both data and template,
anyway it was due to the same expat design problem, which is
the entities that are located in attribute values inside tags.

The solution I have used was just to preserve expat from parsing entities,
and only need 2 additionnal lines in the script (3 with the constant define;).

Just after the input replace the char '' with something else,
and just before the output put it back :

/** Preserve entities from removal */
define('ENTITY_PRESERVE', '£$¥¤');

[...]

#replacement at input :

while ($data = fread($fp, 4096)) {
$data = str_replace('', ENTITY_PRESERVE, $data);  // HERE
if (!xml_parse($this-_parser, $data, feof($fp))) {
die(sprintf(XML error: %s at ligne %d,
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}

[...]

#replacement for output with your code :

function start_tag($parser, $name, $attrs)
{
global $text;
if($name == CUSTOMTEXT) {
$text = $attrs['TEXT'];
$text = str_replace(ENTITY_PRESERVE, '', $text);  // Put '' back !
}
// more tags here ..
}


I am sure that there could be better solutions.
If someone know about one, please email me :)


Cheers
-- 
Gabriel Birke a écrit :
 Hello!

 I've got an XML file that has the following tag:
 customtext text=first linelt;br /gt;second line /

 I parse it with the following handler (simplified a bit):

 function start_tag($parser, $name, $attrs)
 {
   global $text;
   if($name == CUSTOMTEXT)
   $text = $attrs['TEXT'];
   // more tags here ..
 }

 When I echo $text in a HTML page, I see a linebreak - just as I
 intended.

 One of our customers has the script installed on his server and he
 doesn't see a linebreak but sees br / printed out. He has to write
 the tag like this:
 customtext text=first line br /second line /

 Now I've got two questions:
 1. Which tag is correct XML?
 2. What is the cause of this?

 I'm running the script with PHP 4.1.2 and EXPAT Version 1.95.2
 Don't know what our customer has running.

 With best regards

 Gabriel Birke

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Parsing entities in XML attributes

2004-06-23 Thread Gabriel Birke
Hello!
I've got an XML file that has the following tag:
customtext text=first linelt;br /gt;second line /
I parse it with the following handler (simplified a bit):
function start_tag($parser, $name, $attrs)
{
global $text;
if($name == CUSTOMTEXT)
$text = $attrs['TEXT'];
// more tags here ..
}
When I echo $text in a HTML page, I see a linebreak - just as I 
intended.

One of our customers has the script installed on his server and he 
doesn't see a linebreak but sees br / printed out. He has to write 
the tag like this:
customtext text=first line br /second line /

Now I've got two questions:
1. Which tag is correct XML?
2. What is the cause of this?
I'm running the script with PHP 4.1.2 and EXPAT Version 1.95.2
Don't know what our customer has running.
With best regards
Gabriel Birke
--
KONTOR4_Neue Medien
Plathnerstraße 5
30175 Hannover
Fax: +49 51184 48 98 99
mailto:[EMAIL PROTECTED]
http://www.kontor4.de
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php