Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Hello World this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

problem simply stated

 
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
 
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
 
I found some pretty shells, some sea glass and this lovely tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!