Solved

JavaBean to an XML String using XMLEncoder

Posted on 2014-02-04
4
1,002 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java program running SQL query 5 59
glassfish admin console 1 45
Java List 4 73
Strange router problem - can't access hotmail.com 14 105
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…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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.
Suggested Courses

739 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