getChildNodes() and getElementsByTagName()
843834Oct 3 2003 — edited Oct 6 2003hi,
i'm using java's built-in DOM xml parser. i have a very simple xml document:
<?xml version="1.0" encoding="iso-8859-2"?>
<form title="BSA" x="150" y="150" w="240" h="180">
<label name="label1" text="abcd: "
x="10" y="10" w="100" h="20" />
<border>
<label name="label2" text="123"
x="120" y="10" w="100" h="20" />
</border>
</form>
my problem is the following:
i only need the elements that are direct children of the <form> element (or direct children of any other element).
however, if i call the getElementsByTagName("label") method on the <form> element, i get ALL the elements named "label" in the document.
in this case, getElementsByTagName() returns:
<label>
<label>
if i call the getChildNodes() method on the same element, i get twice as many elements as there are direct children in the <form> element.
like this:
getChildNodes() output:
#text
<label>
#text
<border>
i don't know where the "#text" elements come from and what they represent, but there's allways one for each child element.
so, how do you get all direct children of an element?
i coluld just discard the "#text" elements but i'd sitll like to know what they are and whether there could be some other "invisble" "#something" elements.
thanks