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)
 
I had this problem - it did it with spaces for me too. The only way I found to solve it was to generate all my html using the phpdom too - then new lines and spaces don't seem to be a problem anymore.

Obviously that's not very helpful to you, but is it possible to use getElementsByTagName() instead of blindly looking through child elements?
 
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

This is a uni project so code needs to be presentable.

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? :)
 
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.
 
Whoops, but still - could the situation not be explained, or code provided by print or an external viewer rendering it in document tree form?
 
Back
Top Bottom