ID:               21213
 Comment by:       markus dot pfefferle at web dot de
 Reported By:      flying at dom dot natm dot ru
 Status:           No Feedback
 Bug Type:         DOM XML related
 Operating System: All
 PHP Version:      4.3.0RC4
 New Comment:

I stumbled across this bug report because I've just discovered the same
bug and thus would like to reopen this ticket. The bug however lies
with the method set_content(), not with set_attribute, which behaves as
it should behave.

The problematic method here is set_content(). As seen in the code
example, this will resolve entities in the string passed to it. The
question is: why?

Take this for example:

$node->append_child($document->create_text_node('R&D'));
$node->set_content('R&D');

You would expect both lines to do the same thing (provided $node had
previously no child nodes) and result into a serialized XML Document
containing:

<node>R&amp;D</node>

With the method set_content() however it results in this:

<node>R</node>

because it sees the '&' in the parameter as opening of an entity, which
is not valid (and not even closed by ';') and simply omits it.

It only achieves the required result if you do this:

$node->set_content('R&amp;D');

The string passed to create_text_node() does not need to be
entity-resolved simply because there aren't expected to be any XML
syntax elements in there - you can't add more XML sub elements this
way. And so you shouldn't with set_content(). In fact, it gets really
peculiar when you do this:

$node->set_content('" < > &');

Because what you get is only:

<node>&quot; $lt; $gt;</node>

and no &amp; - because even though set_content didn't bother that the
first three XML-syntax-characters weren't escaped as entities (as
create_text_node() wouldn't either), it requires that from '&' - and
that doesn't make sense in my eyes. Either you require entity-escaping
for all characters or none. No mix-mix.

It would be nice if that were fixed.

My PHP version where this bug exists is 4.3.2 windows binary.


Previous Comments:
------------------------------------------------------------------------

[2003-04-09 06:36:22] [EMAIL PROTECTED]

No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.



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

[2003-04-03 09:49:32] [EMAIL PROTECTED]

Please try using this CVS snapshot:

  http://snaps.php.net/php4-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-STABLE-latest.zip

set_attribute_node is now in CVS, can you check it, if it's now
possible, what you intend to do?


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

[2003-01-03 09:35:07] [EMAIL PROTECTED]

As said before, we need set_attribute_node($attrNode) and
append_child() et al. working in attribute Nodes, then it should work.
Don't know, when I have the time to do it, if someone else wants to
take over this part, feel free ;)

chregu

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

[2003-01-03 04:06:32] flying at dom dot natm dot ru

Sorry for summary changing - its Mozilla bug :)

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

[2003-01-03 04:01:49] flying at dom dot natm dot ru

Yes, i agree with you in this point, but it also means, that you should
provide a way to parse given text value and build NodeList of Text and
EntityReference nodes. libxml2 already have such function.

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

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/21213

-- 
Edit this bug report at http://bugs.php.net/?id=21213&edit=1

Reply via email to