aspose file tools*
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
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "problem simply stated" Watch "problem simply stated" New topic
Author

problem simply stated

S lakum
Greenhorn

Joined: Jun 14, 2002
Posts: 9
Hi,
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)
<table-name>hist_client</table-name>
<data-element>
<column-name>camp_id</column-name>
<column-name>ccl_id</column-name>
</data-element>
Help would be so appreciated!
Thanx
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)
{
if("data-element".equals(nextSibling.getNodeName())
{
// 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"
// AS SHOWN ABOVE
Node columnNameTextNode = columnNameElementNode.getFirstChild();
String wantedColumnName = columnNameTextNode.getNodeValue();
}
.........
..........
Please look at the following link for more details on the DOM spec.
http://java.sun.com/xml/jaxp/dist/1.1/docs/api/org/w3c/dom/package-summary.html
S lakum
Greenhorn

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:
nextSibling.getNodeType==nextSibling.ELEMENT_NODE
i get the first as 1 and other as 3rd, ie text and element. Have I defined the dtd wrong?
Thanx
-sunitha
 
wood burning stoves
 
subject: problem simply stated