Padding: 20px 20px; ">
This article describes the configuration function of the "Class Name" tab. You will learn how to specify the corresponding class name and shelling function for the XML element.
If you have not read the first article in this series, read this article first. Otherwise, you cannot read this article.
XML code generator -- Introduction to xmlfactory (1)
The shelling function is powerful and flexible enough to compete with handwritten code. First look at the sample XML:
<Student>
<Name> Xiao Lei </Name>
<Birthday> 1982-06-29 </birthday>
<Education school = "Tsinghua University" Major = "computer"/>
</Student>
Open page: http://www.codingfactory.net/Page/XmlFactory/client/XmlFactory_Flex.html
Stick the above XMLSample XMLMedium, Point"Next"Until"Class Name"Tab, as shown in:
Note that the place in the circle in the red box is operated according to the different schemes A and B respectively. Please compare the generated entity classes.
Solution |
Solution B |
Change the text education to Educ Click "Next" until the "generate code" page is displayed. |
Delete Education Click "Next" until the "generate code" page is displayed. |
Public class student { Public string name {Get; set ;} Public datetime birthday {Get; set ;} Public Educ education {Get; set ;} }Public class Educ { Public String school {Get; set ;} Public String major {Get; set ;} } |
Public class student { Public string name {Get; set ;} Public datetime birthday {Get; set ;} Public String educationschool {Get; set ;} Public String educationmajor {Get; set ;} } |
Solution A is well understood and maps the element <education> to the entity class Educ. Solution B does not generate the corresponding entity class for the element <education>, however, the information contained in the element <education> is not ignored, but mapped to the attributes of the student class.
If you want to save student information to the database (using a table instead of two tables), I think the entity class generated by B is more convenient. We call the operations in solution B as"ShellingOperation. Because the entity class is not generated for the <education> shell, but the "core" such as school and major is retained ". So it is called "Shelling ". Although the shelling operation does not define the class for the element <education>, When you serialize the Student Class Object to XML, the generated XML still includes the <education> element, so you don't have to worry about the XML structure generated after shelling.
Xmlfactory code generator has a powerful shelling function. It not only removes one layer of shell, but also removes several layers of shells until core data is exposed. Let's look at the example below.
<Table>
<Tr>
<TD> 1 </TD>
<TD> 2 </TD>
<TD> 3 </TD>
</Tr>
<Tr>
<TD> 4 </TD>
<TD> 5 </TD>
<TD> 6 </TD>
</Tr>
</Table>
Obviously, the only valuable data is the value in the element <TD>. What kind of entity classes do you want in Form A and B below?
Form |
Form B |
Public class table { Public list <list int32 <> trtd {Get; set ;} } // Describe // The value of table. trtd [0] [0] is 1. // The value of table. trtd [0] [1] is 2. // The value of table. trtd [1] [2] is 6. |
Public class table { Public list <tr> tr {Get; set ;} }Public class tr { Public list <TD> TD {Get; set ;} } Public class TD { Public int32 value {Get; set ;} } |
If you need an object class in the form of a, paste the above XML to "sample XML" and click "Next" until the "generate code" page is displayed. If you need an entity class in the form of B,Class Name"Column, fill in: TR
TD. For example:
Finally, declare that not all elements can be shelled. Under what circumstances can I perform shell removal? I can only simply say"Class Name"Tab, the elements in the second and third tables can be shelled, and the elements in the first table must be mapped to a class. For more information, see the official documentation."Shelling definition and rules"Chapter. Http://www.codingfactory.net/Page/XmlFactory/Help/help_cn.htm