Solved

JavaBean to an XML String using XMLEncoder

Posted on 2014-02-04
4
1,013 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 36

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

696 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