File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes problem simply stated Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "problem simply stated" Watch "problem simply stated" New topic

problem simply stated

S lakum

Joined: Jun 14, 2002
Posts: 9
I just need to know how to move from node 'table-name' to node 'data-element', to node 'column-name'
My purpose here is to get the nodevalue of 'column-name' when i know the 'table-name' nodevalue(simply put- i need the column names of a table)
Help would be so appreciated!
Jayadev Pulaparty
Ranch Hand

Joined: Mar 25, 2002
Posts: 662
Please look at the below psuedo code to get an idea as to how to achieve your object using the DOM API.
I'm assuming that you have the <table-name> Node with you. The following is something what you need to do -
Node nextSibling = tableName.getNextSibling();
// make sure that this is an element node
if(nextSibling.getNodeType == nextSibling.ELEMENT_NODE)
// get the child nodes using getChildNodes()
// loop on the list of child nodes
// make sure that they are element nodes
// make sure their name is "column-name"
Node columnNameTextNode = columnNameElementNode.getFirstChild();
String wantedColumnName = columnNameTextNode.getNodeValue();
Please look at the following link for more details on the DOM spec.
S lakum

Joined: Jun 14, 2002
Posts: 9
Hi Jayadev,
Thanks for ur help.
But I'm not able to work out the solution you've given. This is my DTD structure:
<!ELEMENT table-name (#PCDATA)>
<!ELEMENT data-element (column-name)+>
<!ELEMENT column-name (#PCDATA)>
when I'm comparing:
i get the first as 1 and other as 3rd, ie text and element. Have I defined the dtd wrong?
I agree. Here's the link:
subject: problem simply stated
It's not a secret anymore!