C # Discovery Tour second lecture c#-xslt development

Source: Internet
Author: User
Tags file system parent directory relative web services xpath xslt root directory web database

To get a deeper understanding and use of C #, we started this series of technical lectures on the "C # Discovery Tour". Given that most of you are in the Web database development, and the so-called discovery is found that we are unfamiliar with the field, so this series of lectures will be C # in the Web database development outside the application. The main content of the current planning is graphic development and XML development, and plans to organize a number of courses. In the next C # Discovery Tour, we follow the step-by-step steps to explore and discover the other unknown areas of C #, a deeper understanding and mastery of the use of C # for software development, broaden our horizons, enhance our comprehensive software development capabilities.

This course explains

This course introduces the basic concepts of XPath and XSLT, and describes how to use them in C #.

XPath introduction

XPath is a technology derived from the XML Base specification, designed to quickly retrieve and query XML documents, is easy to use, powerful, and XPath is the basis of XSLT technology.

XPath is a specification defined by the global Organization for international standards to quickly retrieve and locate XML document nodes in a single XML document, and it is cross-platform, and if some software supports XPath, it must support standard XPath syntax. So both Java and C # are XPath that supports the same syntax.

When we understand XPath, we can refer to the file directory structure filepath, in the file directory tree list on the left of Windows Explorer, you can see a variety of file objects, including disk root directory, all levels of file directory, and so on, they together constitute a tree structure, When we select objects, we can find them either in this tree structure, or we can specify the pathname for quick positioning, and the file system path name uses the slash number to separate the directory names of each directory hierarchy. For example, in this diagram, we select the directory, you can use the path name "C:\Documents and Settings\ Ling Yongfu" to quickly locate.

This is also the tree hierarchy in the XML document, so we can also apply the concept of this file pathname to an XML document, thus creating an XPath path. When we work with XML documents, we can find the XML nodes we need at one level, or we can specify XPath path strings to quickly locate the XML nodes. In the XPath path, we use the backslash symbol to separate the names of the XML elements at each level.

In the file directory system, we can use absolute pathname or relative pathname, we can use a dot to represent the current directory, using two points to represent the parent directory. In XPath we also apply a similar concept, the XPath path we specify from the root node of the XML document is the absolute path, and the path that passes from one XML node to the other is relative, and we use a point to represent the current node and two points to represent the parent node. In fact, we can view the absolute path as a relative path from the root node.

In this schematic, the first selected node can be quickly positioned using the XPath path "Table/record/country".

In a file directory system, you cannot have objects of the same name under the same directory, so relative pathname and absolute path names can be accurately positioned on a directory, whereas in an XML document, multiple child nodes with the same name can exist under the same XML node, so the XPath path may Unable to uniquely determine an XML node. In this case, XPath uses the method of embedding conditional judgment statement to solve this problem. An XPath path string can contain a logical expression using a pair of parentheses, in which you can use string judgments, mathematical arithmetic, logical judgments, and predefined functions, and each level in the XPath path can contain a table type. Therefore, the function of XPath's logical judgment is very powerful.

In the schematic diagram, we use the XPath path "table/record[customerid= ' Anatr ']/phone" to quickly locate the second node, where a paragraph bracket is used to contain a logical expression. Represents the lookup of a node in which the text value of the Custoemrid child node is equal to "Anatr".

XPath is an international standard, but in Microsoft's. NET Framework certainly supports this international standard. We can use. NET class library to perform an XSLT transformation in the System.Xml.Xsl.XslTransform type. This type of extension, in addition to the standard XPath, is extended to include functions defined by the developer.

With XPath, we can easily search for any part of the XML document, so it has a good data retrieval analysis function, the recent industry emerging semi-structured document technology is mostly based on XPath.

Because the XPath technology is quite strong, and is the international standard, cross-platform, so everyone has time to learn to use it well. For the detailed syntax of XPath, you can access the Web site Http://www.w3.org/TR/xpath, and if you have a MSDN2003 version installed, refer to the MSDN library/xml Web services/xml core/SDK documentation/ MSXML4.0 Sdk/xpath Reference. These electronic documents are all in English, and you can also buy some Chinese books that specialize in XML technology.

Related Article

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.