x74x61
x74x61

Reputation: 433

DOMAttr's value attribute is confusing?

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.

Upvotes: 1

Views: 642

Answers (1)

Šime Vidas
Šime Vidas

Reputation: 186083

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.

Upvotes: 1

Related Questions