Solved

JavaBean to an XML String using XMLEncoder

Posted on 2014-02-04
4
942 Views
Last Modified: 2014-03-24
Hi,

I was working on below examples
http://www.avajava.com/tutorials/lessons/how-do-i-convert-a-javabean-to-an-xml-string-using-xmlencoder.html
http://www.avajava.com/tutorials/lessons/how-do-i-write-a-javabean-to-an-xml-file-using-xmlencoder.html?page=2

I got output as below.

<?xml version="1.0" encoding="UTF-8"?>
<java version="1.5.0_09" class="java.beans.XMLDecoder">
 <object class="example.MyBean">
  <void property="myBoolean">
   <boolean>true</boolean>
  </void>
  <void property="myString">
   <string>xml is cool</string>
  </void>
  <void property="myVector">
   <object class="java.util.Vector">
    <void method="add">
     <string>one</string>
    </void>
    <void method="add">
     <string>two</string>
    </void>
    <void method="add">
     <string>three</string>
    </void>
   </object>
  </void>
 </object>
</java>




I have not clearly understood this example, output. what is the importance ot Vector object here. Why we need MyBean class as well to generate XML.
How both abve examples are different. How to see java beans inside a xml
please advise
Any links resources ideas highly appreciated. Thanks in advance
0
Comment
Question by:gudii9
  • 3
4 Comments
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
ID: 39834227
what is the importance ot Vector object here.
Vector was just used in the example to show how XMLEncoder can convert an object which is a list of things into the XML that represents that list.
Why we need MyBean class as well to generate XML
You don't need it to generate the XML, it is just an example class of something that you might want to convert to XML.
How both abve examples are different
They are NOT different. You have just posted 2 links to each of the 2 pages of that example. It's all just one example!
How to see java beans inside a xml
I don't understand this question. You are seeing the contents of the javabean in the XML that you posted above.
0
 
LVL 7

Author Comment

by:gudii9
ID: 39843247
How both abve examples are different
They are NOT different. You have just posted 2 links to each of the 2 pages of that example. It's all just one example!


sorry here is the other example link with original link

http://www.avajava.com/tutorials/lessons/how-do-i-convert-a-javabean-to-an-xml-string-using-xmlencoder.html
http://www.avajava.com/tutorials/lessons/how-do-i-write-a-javabean-to-an-xml-file-using-xmlencoder.html

One is example 5 (How do I write a JavaBean to an XML file using XMLEncoder) other one is example 55(How do I convert a JavaBean to an XML String using XMLEncoder?
) under General Java section as below
http://www.avajava.com/tutorials/categories/general-java

specifically difference  between below two examples

One is example 5 (How do I write a JavaBean to an XML file using XMLEncoder)

other one is example 55(How do I convert a JavaBean to an XML String using XMLEncoder?
)

How is writing to XML string example different from XML file example
0
 
LVL 7

Author Comment

by:gudii9
ID: 39880119
Specifically in the below link

http://www.avajava.com/tutorials/lessons/how-do-i-convert-a-javabean-to-an-xml-string-using-xmlencoder.html


author said in first line as below
In another tutorial, we saw how we could use the XMLEncoder class to save a JavaBeanW object to an XMLW file.

I did not get what he meant by another tutorial and how that is different from this link
Please advise
0
 
LVL 7

Author Comment

by:gudii9
ID: 39880123
<?xml version="1.0" encoding="UTF-8"?> 
<java version="1.5.0_09" class="java.beans.XMLDecoder"> 
 <object class="example.MyBean"> 
  <void property="myBoolean"> 
   <boolean>true</boolean> 
  </void> 
  <void property="myString"> 
   <string>xml is cool</string> 
  </void> 
  <void property="myVector"> 
   <object class="java.util.Vector"> 
    <void method="add"> 
     <string>one</string> 
    </void> 
    <void method="add"> 
     <string>two</string> 
    </void> 
    <void method="add"> 
     <string>three</string> 
    </void> 
   </object> 
  </void> 
 </object> 
</java> 

Open in new window



what is the meaning void tag in above generated xml file. From where it came from?

please advise
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now