Every day, people ask questions such as "What is XML", "what can XML do", "Can XML do this for me", and "What will XML Replace. Since I recently used XML for a while, let's talk about my feelings. All of these experiences are simple. Anyone who has used XML has some opinions and opinions, but I just walked through this path and am confused about myself at the beginning. I still remember the misunderstanding, so I will share it with you.
I think beginners may come closer to the following misunderstandings:
1. Is XML a substitute for HTML?
No. The well-written HTML should be a well-formed XML document. It is better not to compare them on a horizontal line for other aspects.
2. Is XML a database collector?
No.
3. Is XML a substitute ...?
None.
This conclusion may sound funny: XML is a very important thing, but it cannot be replaced by anything. But it is not surprising that some people compare it to the ASCII standard. They are the foundation of everything, but they do not (and do not need to) replace anything. (However, just as ASCII replaces some character set definitions that are not big enough, XML will replace some data transmission specifications that you define in your applications, but there is nothing very mainstream .)
When I first started learning XML (or before I started learning it), I would like to ask the following question: what are the benefits of using XML?
I think from a certain point of view, using XML is somewhat like using OO object-oriented:
-You can use it or not.
-If your application is very simple, it is not convenient to use it, and the effect may be worse if you use it.
-Compared with other practical things such as databases, MTS, and Web server, it is more like a concept and a method.
-The larger the project, the more room it can play, the greater the role.
-Once you really understand it, even if you don't use XML parser, It doesn't prevent you from using this concept, just as you can use OO in a specific language.
-......
It seems more abstract.
Let's just give an example. For example, you would like to transfer some data between two modules in the BBS application:
-Spokesman
-Password
-Title
-Content
It is unrealistic to use four parameters, because you may need to expand the function at any time, for example, adding
-Emoticons
It is not possible to add a function each time, and then redefine the function.
So the simplest way is to combine them as a parameter and pass them to the function.
Before XML is available, you may use the separator:
STR = "Spokesman = Zhang San; Password = **; Title = ABC; content = xyz"
Use dictionary, collection, split, and other methods to open the server.
(Of course, you can define the object and structure by yourself, but in most cases, it must be a pure string-for example, another module is not developed by yourself .)
There are several problems with this method of passing strings, which are summarized into two major aspects:
1. Correct Parsing is troublesome. (For example, the title is "Spokesman = James)
2. It is flat and has no hierarchical structure.
You can write some functions to solve these problems. For example, make sure there are "spokespersons" and "passwords" in them. Then write some functions to escape the characters, write some more functions to create hierarchical results...
Enough! Let's use XML. In my current simple understanding:
-XML is used to transmit data.
-XML gives the data a structure-a Tree Structure
-XML has a full set of methods to operate this structure.
-The XML specification (or actual point, XML Parser) helps you determine that the string you created is legal.
-The XML specification (or actual point, XML Parser) has a way to verify this legality
-For the server component that gets this string, you can use the ready-made method in XML to operate it, which is XPath, pattern, similar to a T-SQL statement. (But remember that XML is a tree structure)
-XSLT uses XPath to convert XML (similar to DTS). One of the special cases is to convert XML into HTML output.