-
Posts
492 -
Joined
-
Last visited
Content Type
Profiles
Forums
Events
Posts posted by MrFish
-
-
Strange. I will investigate on that and see what I can find.Could it be a PHP version issue?
-
Hello W3S, I'm trying to use DOMDocument but when i use appendChild its not appending to the element I expect it to. Here is a simple example-
$DOM = new DOMDocument();$DOM->appendChild($DOM->createElement("div"));$DOM->appendChild($DOM->createElement("div"));$DOM->appendChild($DOM->createElement("div"));$DOM->appendChild($DOM->createElement("div"));echo $DOM->saveXML();
What I expect-
<body> <div></div> <div></div> <div></div> <div></div></body>
What I get-
<body> <div> <div> <div> <div> </div> </div> </div> </div></body>
I've looked at the PHP documentation and this looks like how they did it but obviously I'm missing something. Can anyone spot my mistake? Edit: Also, i need to use createElement because I want to manipulate the elements before adding them. When you use new DOMElement() its read only for whatever reason
- 2
-
I'm guessing Notepad2 is Notepad++?Edit:Nope never mind. None of the above.
[SOLVED] DOMDocument Nesting Elements Unexpectedly
in PHP
Posted · Edited by MrFish
That's the same code I used as posted in OP. I checked an old file I used on this same server which printed correctly. Started stripping it down and found it started nesting incorrectly after I took out text nodes. This now works-
But it seems like a cheap trick. How does this page look for you? [ URL REMOVED ] Edit: Oh wait you're right. I was viewing the page through Chromes element inspector. In the HTML it's <div/> like you said. This doesn't register as <div></div> though. Any idea how to make that print differently without text nodes?