• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

write in XML

 
Isaac Ferguson
Ranch Hand
Posts: 922
2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I am using the next code in order to write in my XML but it doesn't works and no error is thrown and it retrieve the values well when I debug it all seems be working but when I open my XML file(from which I read without problem) nothing is written there:




Any idea , please?

Many Thanks,
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You haven't added the elements you have created to the document!
 
Isaac Ferguson
Ranch Hand
Posts: 922
2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

thanks for reply.

What way could I do it , please?

Regards,
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
 
Isaac Ferguson
Ranch Hand
Posts: 922
2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,



I have write like this:



But I get the error:



I am trying to write wchi already exists not create a new one.

Any idea?

Thanks
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reference I gave shows you exactly how to do this. You need to append a root Element and then append your Elements to the root element.
 
Isaac Ferguson
Ranch Hand
Posts: 922
2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

when I try to do that, I get the error:



Any idea?

Thanks
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the rules of XML is that an XML document must have a single root element. The structure of the DOM is such that the "document" has a single child, which is that root element. So you can't add anything to the document because that would result in its having more than one root element.

You should first find the element which you want to add that random stuff to, and then add it there. Don't just add it to the document.
 
Isaac Ferguson
Ranch Hand
Posts: 922
2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im my XMLWriter I have the method writeData which contains this code


Any idea?

Thanks,
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Angus Ferguson wrote:
Any idea?


It is difficult to know how to respond to this. I gave you a reference that presented code that seems to provide the EXACT form of output that you need but for some reason you choose to ignore it. Your latest posting shows that you still do not understand the basics of XML so all I can do is refer you to an XML tutorial - http://www.w3schools.com/xml/ . Although the early pages of the tutorial seem trivial I suggest that you don't skip them.
 
Isaac Ferguson
Ranch Hand
Posts: 922
2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

thanks for reply.

Now I have the code



I have used this code but in my xml file which is something like this:



Now it is woking it is writing but I want add one tag to an existing xml. When I write all the data I had disappear, and I don't want that.

What way could I maintain my old tags too.?


In order to do that I am using code like this but the doc is null it seems is not instantiating the file



I get the error

java.lang.NullPointerException

Any idea?

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic