?
Solved

JavaBean to an XML String using XMLEncoder

Posted on 2014-02-04
4
Medium Priority
?
1,039 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 2000 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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

801 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