Introduction to XML code generator--xmlfactory (iii)
This is a configuration feature that tells us about the Class name tab, and you'll learn how to specify the class name and shelling function for an XML element.
If you have not read the first article in this series, please read this article first, otherwise you can not read this article. Introduction to XML code generator--xmlfactory (i)
The shelling function is very powerful and offers the flexibility to match the handwriting code. Look at the sample XML first:
<Student>
<Name> Ray </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
Paste the above XML into the sample XML , click "Next" until the " Class name " tab is displayed, as shown in:
Note Where the red box is in the circle, we operate according to a, B, two different scenarios, please compare the generated entity classes
| programme a |
Programme B |
Change the text education to Educ Click "NEXT" until the "Generate Code" page pops up |
Delete the education. Click "NEXT" until the "Generate Code" page pops up |
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;} } |
A scheme is well understood, the element <Education> is mapped to the entity class Educ, and the B scheme does not generate the corresponding entity class for the element <Education>, but the element <Education> the information of the envelope: School, The marjor is not ignored, but the mapping becomes the attribute of the student class.
If you are going to store student information in a database (with a table instead of two tables), I think the entity classes generated by the B scheme are more convenient. We call the operation of the B scheme " shelling " operation. Because the entity class is not generated for the <Education> shell, it retains the "kernel" such as school,major. So called "shelling". The shelling operation does not define the class for element <Education>, but when you serialize the Student class object to XML, genetic XML still has the envelope <Education> element, so you don't have to worry about changes in the resulting XML structure after shelling.
Xmlfactory code Generator's shelling function is powerful, not only can take off a shell, but can take off several layers of shell, until the core data exposed. Look at the following example.
<table>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
</table>
It is clear that the only valuable data is the value in element <td>. The following a, B form, do you want that entity class?
| a form |
b form |
public class table { public list<list<int32>> trtd{ get; set; } } //Description //table. The value of trtd[0][0] is 1 //table. The value of trtd[0][1] is 2 //table. The value of 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 entity class A, paste the XML above into the sample XML, then click the Next button until the Generate code page pops up. If you need an entity class in Form B, in the class name column, fill in: Tr Td. Such as:
The final statement: Not all elements, can be shelled operations. Under what circumstances can shelling operations be carried out? I can only simply say " Class name " tab, second, the third table elements, can be shelled; the elements in the first table must be mapped to classes. As for why, I will not open up, interested friends, can refer to the official document "shelling definition and Rules" chapter. Http://www.codingfactory.net/Page/XmlFactory/Help/help_cn.htm
Introduction to XML code generator--xmlfactory (iii)