This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes XML element Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML element" Watch "XML element" New topic
Author

XML element

Maha Hassan
Ranch Hand

Joined: Aug 02, 2005
Posts: 133
Hi all,
I am wondering how to write an xml element,
like i will read some files and based on it i want to generate an xml document.


so how to generate elements i tried Element e = new Element("test");
e.setText("testtest");
but it is not working

anyidea where to start .

thanks
Maha
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

The first thing to understand here is that an Element node can not have any text, so calling the setText() method on it is meaningless.

However an Element node can have children. If you want the element to have a child node with text, then create a Text node, put text in it, and add it as a child of the Element.
Maha Hassan
Ranch Hand

Joined: Aug 02, 2005
Posts: 133

do you meen like this??
another question, if i want to print the output like
<rootelement>some text</rootelement>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML element
 
Similar Threads
Generating Valid XML
Xml Element to Byte Array
XML generation for data in a table
How to create xml dynamic uesing servlet and fill data to fatch from DataBase.
Removing XML declaration in XML file