DOMAttr 的 value 属性令人困惑?
我一直在使用 DOMDocument 及其所有相关类,但有些事情我仍然不清楚。
例如, $domattr->value
http://bla.com/?bla=test&bla2=test
在它应该返回时
http://bla.com/?bla=test&bla2=test
返回(因为这是属性节点文本节点字面上包含的内容)
所以这里是我的问题:
1)为什么它转换&符号:从 DOMAttr 的观点来看,它背后的逻辑是什么的观点?
2)如何使用 DOMNodes 才能获得真实值?
3)处理此类事情时有哪些最佳实践?我希望拥有一致且可预测的代码和行为,但当我没有得到我所期望的结果时,它可能会令人困惑。
I've been working with DOMDocument and all its related classes, but some things are still unclear to me.
For example, $domattr->value returns
http://bla.com/?bla=test&bla2=test
when it should return
http://bla.com/?bla=test&bla2=test
(because this is what the attribute nodes text node literally contains)
So here are my questions:
1) Why is it converting the ampersand: What's the logic behind it from DOMAttr's point of view?
2) How can I work with DOMNodes so that I get the real values?
3) What are some best practices when dealing with this kind of stuff? I want to have consistent and predictable code and behavior, but it can be confusing when I don't get what I expect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编写
、
&
而不是&
的全部目的是因为&
字符在 HTML 源代码中具有特殊含义。当浏览器将 HTML 源代码解析到 DOM 树中时,它会将 HTML 实体(•
等)转换为其对应的字符。无需在 DOM 树中保留 HTML 实体 - 浏览器不会这样做。The whole point of writing
,
&
instead of&
is because the&
character has special meaning in HTML source code. When the browser parses the HTML source code into the DOM tree, it transforms the HTML entities (•
, etc.) into their corresponding characters. There is no need to preserve the HTML entities inside the DOM tree - the browsers don't do that.