HTML Special Chars Dom Problem

Associate
Joined
1 Feb 2006
Posts
1,868
Location
Reading
I have never come across this before. I edit html etc in a text editor and naturally keep my code well presented with new lines and tabs etc.

A problem has arisen now though, when accessing the child elements of a node, new line characters in my source are being counted as nodes :confused:

So instead of firstChild returning the first element of a parent, it returns a node for "/n". Removing the new line in my source gets rid of this but I don't want to have all my child nodes on the same line in the source. This is a uni project so code needs to be presentable.

How can I stop special chars being added to the Dom? Is it to do with charset meta maybe?

(hope you understand what I mean lol)
 
Obviously that's not very helpful to you, but is it possible to use getElementsByTagName() instead of blindly looking through child elements?

I was using the Dom purely for efficiency rather than repeatedly looking for tag names or ID's it was quicker to search once for the container to the objects I required and retrieve information through childNodes.

It's to do with the nature of the DOM and the way it parses the document tree, not an error on your part.

http://developer.mozilla.org/en/docs/Whitespace_in_the_DOM



Why? At the end of the day very rarely is XML viewed natively (and I mean, its main purpose is to simply store structured data, not present it, which is handled by XSLT or an external parser) - so what's the problem? :)

Its a html Dom I'm reffering to not xml.
 
Back
Top Bottom