[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]
Re: [xml-dev] getting elements from xml file using DOM
- From: "Pete Kirkham" <mach.elf@gmail.com>
- To: "Seetha Rama Krishna" <ram_kurra@yahoo.co.in>
- Date: Fri, 1 Sep 2006 17:49:09 +0100
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.
Pete
[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]