When a. NET application converts an object to an XML document and stores the XML file. In fact, XML is used as a portable data storage mechanism because. Net objects are converted to XML and then from XML to Java, and vice versa.
Web objects in XML (wox, woxserializer.sourceforge.net) developed by Carlos jaimez and Simon Lucas is an open-source project to complete this task.
The following is an example of conversion from Java to. Net on its website. The following are student and course classes defined in Java and C.
Figure 3Student and course classes written in Java and C #
- // Java classes
- public class Student
- {
- private String name;
- private int registrationNumber;
- private Course[] courses;
- }
- public class Course
- {
- private int code;
- private String name;
- private int term;
- }
-
- // ***************************************************
- // .NET classes in C#
- public class Student
- {
- private String name;
- private Int32 registrationNumber;
- private Course[] courses;
- }
- public class Course
- {
- private Int32 code;
- private String name;
- private Int32 term;
- }
-
If we use a. Net or Java application to convert the above student and course objects to XML using the wox library. If the application wants to read these objects from XML, it will read the wox library again and convert the XML to Java or. NET object format. Below are the student and course classes converted to XML format.
Java and. Net classes converted to XML
- <object type="Student" id="0">
- <field name="name" type="string" value="Carlos Jaimez"/>
- <field name="registrationNumber" type="int" value="76453"/>
- <field name="courses">
- <object type="array" elementType="Course" length="3" id="1">
- <object type="Course" id="2">
- <field name="code" type="int" value="6756"/>
- <field name="name" type="string"
- value="XML and Related Technologies"/>
- <field name="term" type="int" value="2"/>
- </object>
- <object type="Course" id="3">
- <field name="code" type="int" value="9865"/>
- <field name="name" type="string"
- value="Object Oriented Programming"/>
- <field name="term" type="int" value="2"/>
- </object>
- <object type="Course" id="4">
- <field name="code" type="int" value="1134"/>
- <field name="name" type="string" value="E-Commerce Programming"/>
- <field name="term" type="int" value="3"/>
- </object>
- </object>
- </field>
- </object>
-
Call wox in your application to convert XML to. Net or Java objects.