. NET and Java object XML serialization library wox

Source: Internet
Author: User

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 #


  
  
  1.           // Java classes
  2. public class Student
  3. {
  4.   private String name;
  5.   private int registrationNumber;
  6.   private Course[] courses;
  7. }
  8. public class Course
  9. {
  10.   private int code;
  11.   private String name;
  12.   private int term;
  13. }
  14.  
  15. // ***************************************************
  16. // .NET classes in C#
  17. public class Student
  18. {
  19.   private String name;
  20.   private Int32 registrationNumber;
  21.   private Course[] courses;
  22. }
  23. public class Course
  24. {
  25.   private Int32 code;
  26.   private String name;
  27.   private Int32 term;
  28. }
  29.        

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


  
  
  1. <object type="Student" id="0">
  2.   <field name="name" type="string" value="Carlos Jaimez"/>
  3.   <field name="registrationNumber" type="int" value="76453"/>
  4.   <field name="courses">
  5.     <object type="array" elementType="Course" length="3" id="1">
  6.       <object type="Course" id="2">
  7.         <field name="code" type="int" value="6756"/>
  8.         <field name="name" type="string"
  9.           value="XML and Related Technologies"/>
  10.         <field name="term" type="int" value="2"/>
  11.       </object>
  12.       <object type="Course" id="3">
  13.         <field name="code" type="int" value="9865"/>
  14.         <field name="name" type="string"
  15.           value="Object Oriented Programming"/>
  16.         <field name="term" type="int" value="2"/>
  17.       </object>
  18.       <object type="Course" id="4">
  19.         <field name="code" type="int" value="1134"/>
  20.         <field name="name" type="string" value="E-Commerce Programming"/>
  21.         <field name="term" type="int" value="3"/>
  22.       </object>
  23.     </object>
  24.   </field>
  25. </object>
  26.        

Call wox in your application to convert XML to. Net or Java objects.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.