Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Empty Nodes Weird Problem

Status
Not open for further replies.

ca4928

Programmer
Jan 4, 2005
13
GB
I started with XML this morning, and after playing arund with it for a while, I've found my problem. Every Alternate childNode for every Node in my document is an empty blank node.


For example

<DOCUMENT>
<ONE>Hello</ONE>
<TWO>Goodbye</TWO>
</DOCUMENT>

using javascript

documentElement.childNodes[1].childNodes[0]=Hello
documentElement.childNodes[3].childNodes[0]=Goodbye

I think that these should be accessed as childNodes[0] and [1], but they are not. If i try to access these i get an error.

documentElement.childNodes[0].childNodes[0]
documentElement.firstChild.childNodes[0]
documentElement.lastChild.childNodes[0]
'Error, (document.childNodes[0] || document.firstChild) has no properties'

Does anyone know what the problem is? If it is a problem!
 
You have line breaks (whitespace) in your XML.


If you have no line breaks:

<DOCUMENT><ONE>Hello</ONE><TWO>Goodbye</TWO></DOCUMENT>

It will behave as you expect. But at the moment, you essentially have:

<DOCUMENT>#text<ONE>Hello</ONE>#text<TWO>Goodbye</TWO>#text</DOCUMENT>

Jon

"I don't regret this, but I both rue and lament it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top