• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Difference between Element and Node

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the basic difference between Element and Node in Java. I just cam across this while manipulating XML node.

Also is there any way where I can set value for particular node/element?
ie <Name></Name> should be changed to <Name>Bob</Name>
I am not able to do it. But I can very well set attribute within the node,
for example <Name value="Bob"/>
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Yogesh.

What XML API are you using? JDOM? NanoXML? Xerces?

I suspect you need to look for a method called setText(String) or addContent(String) on the Element object you're referencing.

J
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess you are talking about interface Node and interface Element in package org.w3c.dom. Have you looked at the API documentation for those interfaces?

Element is a subinterface of Node. An Element represents an element in an XML document, so something that begins with a start tag and ends with an end tag. An Element is a Node, but there are other things besides Element which are also Nodes. For example, attributes, comments etc. are also Nodes, but not Elements.

The org.w3c.dom API is not very well suited for editing XML documents - it is meant mainly for reading XML documents. If you want to edit XML documents, an API like JDOM is much easier to use.
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jesper Young:

Please do not recommend jdom to new user any more. Jdom has stopped development on 2004. It is getting obsolete now. Don't get me wrong, I am using jdom since the very early edition, and directly got the idea from one of jdom authors in person.

However, things have changed now. Please use xerces, dom4j, xpp, etc. instead.

Thanks!
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This gets deep into personal preference territory, so I'll plug my favorite library for creating and manipulating XML: XOM.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are going to use the DOM in the standard Java library you should get really familiar with the table in the Javadocs for the Node interface in the org.w3c.dom package. There are 12 different subinterfaces of Node - each with its own peculiarities summarized in that table.

Bill
 
What's a year in metric? Do you know this metric stuff tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic