Jump to content

MrFish

Members
  • Posts

    492
  • Joined

  • Last visited

Posts posted by MrFish

  1. 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-

    $DOM = new DOMDocument();  $div = $DOM->createElement("div");  $div->appendChild($DOM->createTextNode(""));$DOM->appendChild($div);  $div = $DOM->createElement("div");  $div->appendChild($DOM->createTextNode(""));$DOM->appendChild($div);  $div = $DOM->createElement("div");  $div->appendChild($DOM->createTextNode(""));$DOM->appendChild($div);  $div = $DOM->createElement("div");  $div->appendChild($DOM->createTextNode(""));$DOM->appendChild($div);echo $DOM->saveXML();

    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?

  2. 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

    • Like 2
×
×
  • Create New...