Solved

JavaBean to an XML String using XMLEncoder

Posted on 2014-02-04
4
960 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

919 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

12 Experts available now in Live!

Get 1:1 Help Now