Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xml-dev] getting elements from xml file using DOM

From: "Pete Kirkham" <mach.elf@-----.--->
To: "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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent