943,881 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 379
  • Java RSS
Jul 28th, 2009
0

adding values to xml

Expand Post »
hi there,
how can I change string to xml and vise verse in java, in addition how can I add values to xml according to element name ,
I can imagine something like "setValue(elementName, the value) ; as we are using in java,

any suggestions any help , please!
thanks in advance
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
knowledgelover is offline Offline
86 posts
since Nov 2007
Jul 28th, 2009
0

Re: adding values to xml

You might want to look into the Java XML API, W3C DOM API and its implementations like Xerces. The Xerces XML parsing library comes bundled with your Java runtime. A simple Xerces program:
Java Syntax (Toggle Plain Text)
  1. public class Test {
  2.  
  3. public static void main(final String[] args) throws Exception {
  4. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  5. DocumentBuilder builder = factory.newDocumentBuilder();
  6. System.out.println(factory + "\n" + builder);
  7. InputSource in = new InputSource(new StringReader(
  8. "<?xml version='1.0'?><root><child value='1'/></root>"));
  9. // The doc now contains the entire XML hierarchy
  10. Document doc = builder.parse(in);
  11. }
  12.  
  13. }
BTW, if all you need to do is manipulate your XML files in memory, go for a Java specific solution like JDOM.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
Jul 28th, 2009
0

Re: adding values to xml

hi,
thank you very much, I am giving it a try
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
knowledgelover is offline Offline
86 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: How to open a text file to view using java
Next Thread in Java Forum Timeline: StockTrackerDB login error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC