-
Notifications
You must be signed in to change notification settings - Fork 7.9k
DOMNameSpaceNode parent not unset when namespace gets unlinked. #12850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
…s unlinked The problem is that the namespace nodes are exposed as fake nodes because of their different underlying data structure, which means that the parent link isn't actually updated when it gets removed; and we don't have a simple way of tracking it. So just perform a check for the node type and check whether the namespace declaration associated with the fake node is still in existence.
…s unlinked The problem is that the namespace nodes are exposed as fake nodes because of their different underlying data structure, which means that the parent link isn't actually updated when it gets removed; and we don't have a simple way of tracking it. So just perform a check for the node type and check whether the namespace declaration associated with the fake node is still in existence.
…s unlinked The problem is that the namespace nodes are exposed as fake nodes because of their different underlying data structure, which means that the parent link isn't actually updated when it gets removed; and we don't have a simple way of tracking it. So just perform a check for the node type and check whether the namespace declaration associated with the fake node is still in existence.
Hello, First of all, thank you nielsdos for your courage. DOM extension is not an easy task. It's so strange... I would have bet that In any case according to the documentation, removeAttributeNode() expect a DOMAttr object and never a DOMNameSpaceNode
Since XML declarations( So here it is how it should work for me : <container xmlns="urn:foo" xmlns:my="urn:my" my:at="value">
<child my:at="val"></child>
</container> $dom = new DOMDocument;
$dom->loadXML("<container xmlns=\"urn:foo\" xmlns:my=\"urn:my\"><child my:at=\"val\"></child></container>");
$container = $dom->documentElement;
$child = $dom->documentElement->childNodes->item(0);;
$fooUrn = $container->getAttribute("xmlns");
$fooUrn = $container->getAttributeNs("http://www.w3.org/2000/xmlns/", "");
$defaultNs = $container->getAttributeNode("xmlns");
$defaultNs = $container->getAttributeNodeNs("http://www.w3.org/2000/xmlns/", "");
$myUrn = $container->getAttribute("xmlns:my");
$myUrn = $container->getAttributeNs("http://www.w3.org/2000/xmlns/", "my");
$myNs = $container->getAttributeNode("xmlns:my");
$myNs = $container->getAttributeNodeNs("http://www.w3.org/2000/xmlns/", "my");
$nodeAt = $child->getAttributeNodeNs("urn:my", "at");
//var_dump(...);
// 3 ways to remove my:at="val"
//$ret = $child->removeAttribute("my:at");
//$ret = $child->removeAttributeNode($nodeAt);
//$ret = $child->removeAttributeNs("urn:my", "my");
// 3 ways to remove xmlns="urn:foo"
//$ret = $container->removeAttribute("xmlns");
//$ret = $container->removeAttributeNode($defaultNs);
//$ret = $container->removeAttributeNs("http://www.w3.org/2000/xmlns/", "");
// 3 ways to remove xmlns:my="urn:my"
//$ret = $container->removeAttribute("xmlns:my");
//$ret = $container->removeAttributeNode($myNs);
//$ret = $container->removeAttributeNs("urn:my", "at");
var_dump($ret);
echo $dom->saveXML(); The xmlNs.context field was added on June 16, 2006. DOMNameSpaceNode could use this field to store the xml parent node/doc, and keep _private to link to the zend_object PS : I would go for a new extension, but my wife is calling me ... |
Hey
It certainly isn't 😅
Yeah the current behaviour is indeed completely wrong. In fact, the namespace handling is totally whack :/ Thanks for sharing your code sample, might be useful as a reference, it is indeed how it's supposed to work. I'm tempted to leave this issue as-is. I'm currently researching the possibility of making ext-dom spec compliant in an opt-in way. For background, we currently have new classes
Perhaps, although we have to maintain this after cloning etc so libxml probably makes it a bit harder...
😂 |
@nielsdos This issue is mentioned as fixed by the opt-in compliance RFC or am i missing something? |
It's no longer an issue in spec compliance mode because it doesn't have the class at fault. For old DOM the issue is still here. I'm uncertain about how to fix this in old DOM, which is why this issue is still open. |
I looked into this again.
For the first use-case, we do want to keep the parent node because XPath basically demands that a namespace node is tied to the particular parent that it was scoped upon when the query was executed. For the second use-case, i.e. the one highlighted in this issue, we would ideally unlink from the parent if the namespace gets unset. However, this can't be implemented in an efficient way as far as I can tell. |
Description
The following code:
Resulted in this output:
But I expected this output instead:
In versions prior to 8.1 the parent node was always NULL.
Mainly creating the issue so I don't forget about this.
PHP Version
8.1+
Operating System
No response
The text was updated successfully, but these errors were encountered: