Technical Principles of QBlog in the autumn Garden: webpage processing-content filling (8)

Source: Internet
Author: User

Review:

1. Analysis of QBlog technology principles in the autumn Garden: Opening part: Overall understanding (1) -- introduces the role of the overall folder and file

2: Analysis of QBlog technical principles of the autumn color Garden: Understanding the whole site processing process (2)-introducing the business processing process of the autumn color Garden

3: Analysis of QBlog technical principles in the autumn color Park: UrlRewrite's principle of URL without a suffix (3) -- introduces how to implement URL without a suffix

4: Analysis of QBlog technical principles in the autumn Garden: URL redirection System of UrlRewrite (4) -- introduce how to locate the processing program in the URL

5. Technical Principles of QBlog in the autumn color Park: Module-based page base class design (5)-Introduction to creating base classes and custom lifecycles

6: Analysis of QBlog technology principles in the autumn Garden: Module Page Base-Lifecycle Process (6)-Introduction to internal services of the basic Lifecycle

7. Technical Principles of QBlog in the autumn Garden: Module-based lifecycle-page loading (7)-Introduction to html Loading Principles

 

Ps: QBlog: Http://www.cyqdata.com/download/article-detail-427

 

In the previous section, we analyzed how html is loaded and displayed.

This section describes how to fill in the html content in the QBlog of the autumn garden.

 

Tip:

Many netizens said they could not understand the content of this section. The main reason is that this series is highly correlated. It is best to first understand the content of the previous section to better read and understand the content of this section.

Note:

1: The content in this section has exceeded the processing range of Web. dll, So I corrected the title.

2: in the previous section, there is another multi-language translation that is not resolved. Therefore, the next section will first add the multi-language translation content and add the demo content for this section.

 

I. Common Operations and filling

 

For example:

In the upper-right corner, there is a user name with a link: cyqdata

 

After loading html normally, obtain A link node based on the ID and fill in the content, the Code required is roughly:

XmlDocument xDoc = new XmlDocument ();
Try
{
XDoc. Load ("xml file path ");
XmlNode xNode = xDoc. SelectSingleNode ("xpath Syntax ");
If (xNode! = Null)
{
XNode. InnerText = ": cyqdata"; // fill in the username
If (xNode. Attributes ["href"] = null) // fill in the user name Link
{
XmlAttribute attr = xDoc. CreateAttribute ("href ");
XNode. Attributes. Append (attr );
}
XNode. Attributes ["href"]. Value = "http://www.cyqdata.com /";
}
}

 

Think hard:

How hard is it to develop a node that needs to write such a long code?

To assign values to Xml operations, consider the following: <! [CDATA [content with special characters]> to parse complex content.

 

Without a good idea to simplify the code, it would be difficult to develop it. After writing the code, it would be as thick as several books.

The writing is painful, and it seems uncomfortable. The maintenance personnel have to jump to Foxconn.

 

To save the suffering of the world, XmlHelper was born after many days and nights, and its appearance simplified this development to the point of hard and hard to imagine, this greatly saves the amount of code and increases the development speed.

 

Ii. XmlHelper

 

In the previous example, the page html loading is completed, and the content is then added to various ashx handlers.

 

SeeXmlHelper shot,Fill in the above User Name:

 

Method 1: public void Set (string id, SetType setType, params string [] values );

Document. Set ("labUserName", SetType. A, "Autumn Garden: cyqdata", "http://www.cyqdata.com /");

With this method, just one line is enough. [What is Document? In fact, it is the object defined by XmlHelper. In the example above, attributes are defined in the base class, so each ashx can directly obtain]

Introduction:

This method is only used to fill a single node. SetType has many html Tag types. You can select different tags based on different types.

At the same time, this method also has several reloads. For detailed usage, please first read the CYQ. Data API documentation, and then write the tutorial Article later, so stay tuned.

 

Of course, most of the time, the value is not fixed, usually reading a lot from the database, in order to better and CYQ. a better combination of the MAction series under Data makes it easier to use and finally introduces another method:

 

Method 2:

Public void LoadData (MDataRow row );

Public void SetFor (string id, SetType setType, params string [] values );

 

Let's take a look at how the two methods work together to reduce the source and consumption. First:

 

, With the user's blog title andBlogIntroduction, as well as user profiles, all of which have to be read from the database. What is the code?

Document. LoadData (DomainUser );
Document. SetFor (IDKey. labSpaceName, forAdmin? SetType. InnerText: SetType. InnerXml );
Document. SetFor (IDKey. labSpaceIntro, forAdmin? SetType. InnerText: SetType. InnerXml );
If (! ForAdmin)
{
Document. SetFor (IDKey. labCustomCss );
}

 

This is the code used in the autumn Garden. The user's front-end and backend are added with a small branch.

Note:

How does SetFor retrieve data from DomainUser (MDataRow? The key is the agreed ID.

For example, labSpaceName reads the value of the SpaceName field in MDataRow by default. After conventions are adopted, the Set method is called internally.

The above two methods show that, in the end, only one node is filled.

 

In fact, most of the page content is filled out in a list loop.

 

Next, let's look at a very traditional list loop diagram:

 

If you develop code in the traditional way, the following code should be generated:

Using (MAction action = new MAction (TableNames. Blog_Content ))
{
MDataTable table = action. Select (); // obtain the table
XmlNode tableNode = Document. GetByID ("tableID"); // extract the table Node
XmlNode child = tableNode. ChildNodes [0]. Clone (); // copy the tr node to be recycled.
TableNode. RemoveAll (); // clear all child nodes
Foreach (MDataRow row in table) // loop row
{
XmlNode newTrNode = child. Clone (); // copy a row
NewTrNode. InnerText = row. Get <string> (Content. Title );
// Then assign the second value .. The third value... 27 are omitted here
TableNode. AppendChild (newTrNode); // load the row
}
}

 

The above code is barely squeezed out, And the MAction of CYQ. Data can be used in this way.

If you use other frameworks to write code, you don't have to wait for the Code. Try CYQ. Data.

However, I think it is incredible to write too much.

 

When there are many attribute nodes in the process of its loop, there will be hundreds of lines of code written in one loop.

Oh, my God. There are several more cycles to write. The pain is that you have to wait in line to buy tickets and then wait in line to jump to the building...

In order to make the world a more thorough rescue, ten days after pregnancy finally gave birth to another method...

 

Method 3:

Public void LoadData (MDataTable table );

Public void SetForeach (string id, SetType setType, params object [] formatValues );

 

Introduction:

Familiar with it: Set, SetFor, and SetForeach are a family.

Let's talk about how to simplify SetForeach:

Using (MAction action = new MAction (CustomTable. ArticleView ))
{
Document. LoadData (action. Select ());
Document. setForeach ("tableID", "<li> <a href = \" "+ Config. httpHost + "/{0}/article-detail-{1} \" >{2} </a> </li> ", Users. userName, Content. ID, Content. title );
}

 

Look, look, look, know how much it saves.

 

However, the situation is often complicated. In the process of loop, what should be processed twice in most cases? Why?

This will certainly appear in the autumn garden. For example, the style of the paging control is a situation.

 

Add an event, Document_OnForeach (string text, object [] values, int row)

See Usage:

Using (MAction action = new MAction (CustomTable. ArticleView ))
{
Document. LoadData (action. Select ());
Document. OnForeach + = new XmlHelper. SetForeachEventHandler (Document_OnForeach );
Document. setForeach ("tableID", "<li> <a href = \" "+ Config. httpHost + "/{0}/article-detail-{1} \" >{2} </a> </li> ", Users. userName, Content. ID, Content. title );
}

String Document_OnForeach (string text, object [] values, int row)
{
// Text is the cyclic label content
// Values is the row value.
// Row indicates the row to which the loop is generated.
// Finally, you can handle what you like, and return text at the end;
}

 

Summary:

Based on the autumn Garden(MVQ [MV autumn mode for short])No killer framework is developed, but it cannot be. How much sweat does it have to get tired? How much blood does the boss get? How many months does the cycle take?

Therefore, the best way is to use the help of Set, SetFor, and SetForeach to develop things, such as dreams, treasure, high cost performance, and extraordinary ideas. Give it a try, it's easy to use. It's so happy and exciting.

Everything is done:CYQ. Data(Video) Tutorial address:Http://www.cyqdata.com/cyqdata

CYQ. Data Support Hotline: http://www.cyqdata.com/cyqdata/article-detail-28641

 

Next section: analyze the autumn garden for youQBlogIt is the Post event principle and will produce at the same timeXmlHelperFor more information, see.

 

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.