You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Son To <so...@gateway.homeip.net> on 2001/01/27 00:06:28 UTC

Node.getFirstChild() wierdness

Hi,
I am using DOM. There seems to be an extra Node in the Document object
that is returned

for example, 

<address>
    <street>3134 Broad Street</street>
    <city>Philadelphia</city>
    <state>Pennsylvania</state>
    <zip>19143</zip>
</address>

document.getDocumentElement().getFirstChild().getNodeName() 
returns "#text" when I expected it to return "street"

root.getDocumentElement().getFirstChild().getNextSibling().getNodeName()
returns "street"

what is that "#text" being returned? Shouldn't the firstChild of address 
be street?

I tried various other xml documents, and "#text" is always the firstChild.
Am I misunderstanding the DOM tree? If so how is this address represented
in the DOM tree?

thanks,
son


Re: Node.getFirstChild() wierdness

Posted by Tom Bradford <br...@dbxmlgroup.com>.
Son To wrote:
> <address>
>     <street>3134 Broad Street</street>
>     <city>Philadelphia</city>
>     <state>Pennsylvania</state>
>     <zip>19143</zip>
> </address>

The way that the DOM gets created matches the structure of the
Document.  in this case, you'll have:

Element name="address"
   Text name="#test" value="\n   "
   Element name="street"
   ...

> document.getDocumentElement().getFirstChild().getNodeName()
> returns "#text" when I expected it to return "street"

Because there is character data in the file, it becomes part of the
resulting DOM tree.  You have to expect that there will be Text nodes.

-- 
Tom Bradford
Founder & Chief Architect
The dbXML Group, L.L.C.
http://www.dbxmlgroup.com