OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] getting elements from xml file using DOM

On 01/09/06, Seetha Rama Krishna <ram_kurra@yahoo.co.in> wrote:
> can any body tell me how can i get first level of elements in the xml file
Since you are using DOM, you have a tree of objects which represent
all the nodes in the document.

The object representing an element will have methods to access the
objects representing the child nodes of that element.

documentElement  will be the object representing the Date element.
documentElement.getChildNodes() will return a NodeList representing
the first level of nodes under the document element.

For your document,
documentElement.getElementsByTagName("Today").item(0) will return the
Today element which is a child of the document element.

Alternatively, you can iterate over the NodeList returned by
documentElement.getChildNodes() for the first Node which is an Element
(using getNodeType()), and test its local name (some of the nodes will
be Text nodes which contain white space). That will guarantee it's the
Today element in the first level of nodes under the document element.

Your example XML is invalid, so I'm making some assumptions about what
the structure should be.


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS