Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to parse XML file using JDOM?

Status
Not open for further replies.

jollyplay

Programmer
Dec 16, 2003
90
Hi,

I am using JDOM to parse the xml file. I'm able get the text value from the xml file.

I'm havaing a xml file like this,

<config>
<database>
<tableName>emp</tableName>
<columnName>
<column>id</column>
<column>dept</column>
</columnName>
<database>
</config>

I need to get the column names in an array. I don't know how to get it. Kindly give me some idea to solve this issue.

Thanks in advance.
 
You need to create a DocumentBuilderFactory and from that get an instance of a DocumentBuilder.

Use the parse method of the DocuementBuilder to create a Document.

Acquire a NodeList containing your column nodes using the getElementsByTagName method of the top level Element. (Use the getDocumentElement method on the Document to get the top node as an Element).

The NodeList can be iterated and the text contents of each element node move to your array.

The packages org.w3c.dom and java.xml.parsers should guide you.

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top