Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

DOM Parse return "#text" instead of node name...

807601Jun 9 2008 — edited Jun 10 2008
This is my xml file:
<recipelist>
&#8722;
	<recipe>
<name>couscous</name>
&#8722;
	<categories>
<category>Side Dish</category>
<category>Vegan</category>
</categories>
<link>couscous.xml</link>
</recipe>
&#8722;
	<recipe>
<name>damper</name>
<description>
  A recipe for traditional Australian damper.
  </description>
&#8722;
	<categories>
<category>Bread</category>
<category>Snack</category>
</categories>
<link>damper.xml</link>
</recipe>
</recipelist>
and this is my DOM: the crrnode is the category value i look up.
The parent is <category>; grandParent is <categories> and grandma is <recipe>
They are all display on the screen except the sibling of grandParent --> name, description and link --> they display "#text" as Name and "3" as Type

recipe
#text
#text
categories
#text

like that. And here is my DOM:
case Node.TEXT_NODE: {
	  Node parent = currnode.getParentNode();
	  if (parent != null) {
	  	Node grandParent = parent.getParentNode();
		if ((grandParent.getNodeName().equals("categories")) && (parent.getNodeName().equals("category"))) {
		
		  String text = currnode.getNodeValue();
		  if (text.equals("Main Course")) {
		  	if (text.length() > 0) {
			
			  Node grandma = grandParent.getParentNode();
			  Node name = grandma.getFirstChild();
			  Node des = grandParent.getPreviousSibling();
			  Node link = grandma.getLastChild();
			  
			  out.println("<h1>"+grandma.getNodeName()+"</h1>");
			  out.println("<h1>"+name.getNodeName()+"</h1>");
			  out.println("<h1>"+des.getNodeName()+"</h1>");
			  out.println("<h1>"+grandParent.getNodeName()+"</h1>");
			  out.println("<h1>"+link.getNodeName()+"</h1>");
I'm so desperate with these. I search and do it myself for my assignment and so so ... fresh about these DOM. I have also post 2 other thread about getParameter() to DOM to look up the traverse tree, but also desperate.

Plz help me, and tell me what to do.
Thx alot
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 8 2008
Added on Jun 9 2008
4 comments
3,412 views