XML code generator -- Introduction to xmlfactory (2)

Source: Internet
Author: User
It has been a long time since I wrote the previous article because of the Spring Festival and the launch of the project. I don't know if there are too many things or if my efficiency is too low. In short, the time is not enough.
Ah, a hard-pressed programmer. I hope that what I write will save you time.

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)

In the previous article, XML in RSS format is used to describe how to use xmlfactory to generate entity classes and XML serialization and deserialization code. However, when you click"Next"Until the code is generated, the role of each tab is not described in detail. The following articles describe all the configuration items on each tab.


This article describes the configuration function of the "element/subvalue" tab. You will learn how to adjust the structure of XML elements and the impact on generating object classes.

I,Roles of "multiple" columns in the subvalue list
First, add the sample XML:
<Select id = "select1">
<Option value = "1"> ABC </option>
</SELECT>

This is too simple. Select objects in HTML.
Old look, open this address http://www.codingfactory.net/Page/XmlFactory/client/XmlFactory_Flex.html
Stick the above XMLSample XMLMedium, PointNext; Display as shown in
The list on the left shows all elements, and the list on the right shows all the sub-values included in the element. When code is generated in the future, the elements on the left will be mapped to the object class (if not shelled, this will be discussed later). The child values on the right should be shot as class attributes.

In this XML, the element <SELECT> package contains two sub-values: attribute ID and element <option>.
Obviously, in actual situations, a <SELECT> should include multiple <option>, so it should be mapped to such an object class: public class select
{
Public String ID {Get; set ;}
Public list <option> Option {Get; set ;}
}

How can the Code Generator determine whether a subvalue is mapped to a class attribute in the complex form?
It is specified through the "multiple" columns in the "subvalue List". If the check box of this column is selected, the subvalue should bePlural FormOtherwise, the ing isSingular form.
For example:

Whether to select "multiple" Columns Generated entity class
Selected Public class select
{
Public String ID {Get; set ;}
Public list <option> Option {Get; set ;}
}

Not selected Public class select
{
Public String ID {Get; set ;}
Public option {Get; set ;}
}

There are several questions to clarify:
1. Why are there no check boxes available for the "multiple" columns in the row of the sub-value ID?
A: Id is a subvalue of the attribute type. It cannot have multiple values. Therefore, when mapped to a class property, only the singular form is used.

2. What types of subvalues are available?
Answer: There are three types: element, attribute, and value. You can see the type of the sub-value in the "type" column of the "sub-Value List.

Subvalue type Example Description Yes
Class attributes mapped to the plural form
Element <Div> <p> 1234 </P> </div> Element <p> is the element type subvalue of element <div>. Yes
Attribute <Div id = "div1"/> ID is the attribute class sub-value of the element <div>. No
Value <P> 123 </P> The text "1234" is a subvalue of the Value Type of the element <p>. No

II,Edit and configure the structure of each XML Element

Sometimes the child values we need are missing in the sample XML. For example, the element <SELECT> in this example usually includes the name attribute in actual applications. We have two ways to solve this problem. The first method is to complete the sample XML, and then use the code generator to re-analyze it. The other method is more intuitive and directly uses the "Add sub-value" function.

Operation:
1. select items in the list on the left, and then click "add subvalue. This indicates that you want to add a subvalue to the <SELECT> element.
2. In the pop-up dialog box, select "attribute" for "subvalue type" and enter "name" for "element name ".


In particular, if we add a new subvalue of the "element" type to the element. For example, add <span> to <option>. After the operation is completed, a span item is automatically added to the left-side list; however, if you click "Next", the system will prompt an error (for example ). This is because the newly added element <span> does not include any sub-values, and the code generator does not allow empty sub-value elements to be mapped to classes (you will not define entity classes without any attributes, right ?) Therefore, we need to select this item (SPAN) and then use the "add subvalue" function to add a subvalue to it.


For redundant XML elements that you think do not need to be mapped to a class, you can use the "delete element" function to delete the elements. After deletion, all elements will no longer contain child values of this type. When code is generated later, the corresponding entity class will not be generated for this element.


The "delete sub-value" function is to delete the sub-value of an element. When code is generated in the future, the corresponding entity class will still be generated for this element, however, the child values you delete will not be mapped to the attributes of the class.

The code generated in this example is as follows:

Http://www.codingfactory.net/Page/XmlFactory/OutPut/XmlCSharp.aspx? Id = 9151



It should be noted that the author also changes the class property name on the "class property" tab to form the code above. This document does not show specific operations. This will be explained in subsequent articles.

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.