Altova Mailing List Archives>Archive Index >xml-dev Archive Home >Recent entries >Thread Prev - Re: [xml-dev] getting elements from xml file using DOM [Thread Next] Re: [xml-dev] getting elements from xml file using DOMTo: "Seetha Rama Krishna" <ram_kurra@-----.--.--> Date: 9/1/2006 4:49:00 PM On 01/09/06, Seetha Rama Krishna <ram_kurra@y...> 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.
Pete | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
