This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem simply stated

 
S lakum
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic