SoFunction
Updated on 2025-04-08

XML Classic Q&A

1. HTML has become so popular, why should XML be developed?

Simply put, HTML cannot complete, we hope XML will complete the tasks. The reason is very simple. The tasks to be completed by XML must be completed by meta-mark language, while HTML is just an instance mark language. Before XML was released, the development of the international Internet was bound by the following issues of HTML:
1) HTML cannot describe the data content, and this is exactly what is necessary for data retrieval and e-commerce.
2) HTML's ability to describe data performance is very insufficient. For example, HTML cannot describe objects such as vector graphics, scientific symbols, etc., and currently can only express these objects through images.
3) The status of HTML instance markup language is completely unable to adapt to the development needs of new markup needs.
The emergence of XML has made the above problems well resolved.
Just imagine in the Internet world, if everyone speaks dialects and needs to translate when exchanging information with each other, what a world that would be difficult to communicate and communicate. In the Internet world, XML is important precisely because it plays the role of "international language". In addition, XML provides the Internet world with tools to define "professional terms" in various industries.

2. How to read XML in the browser?

Tools for reading XML documents are generally called XML parsers, also known as XML processors. The XML processor transfers data to the application software for processing, publishing, querying, or displaying. XML does not provide an application program interface (API) to the application software, it only passes data to the application software. The XML processor does not parse non-well-constructed data. Both Netscape and Microsoft have included XML parsers in their browsers. The XML developer community provides free XML readers and parsers for application in application software or XML production software.

3. Why use XML instead of HTML?

There are six more important reasons:
1) Authors and vendors can use XML to design their own document types without being bound by HTML.
2) Because XML's hypertext linking ability is much stronger than HTML, the information provided by XML is richer than HTML and easier to use.
3) XML can provide more and better mechanisms to facilitate the browser's information performance and optimize performance.
4) XML abandons the complexity of SGML, so it will be easy to write applications that process XML.
5) Information is easy to store and can be reused.
6) XML files can also be used in SGML environments and are not necessarily limited to use in WEB.

4. Can XML files be created and managed in Java?

Yes, any programming language can be used to output data from source documents in XML form. Many front-end and back-end tools have emerged to make programming and data management more convenient. The following two URLs have more detailed explanations: /XMLdb_0_1.htm

5. Why are the analysis results of XML files garbled?

This is caused by coding problems. The XML standard stipulates that the XML analyzer must support "UTF-8" and "UTF-16" encodings, and must be able to automatically distinguish the two encoded files. It does not require support for other encodings (including the commonly used Chinese encoding "GB2312" or "BIG5". If the XML file contains an encoding declaration, the analyzer will process it according to the declaration encoding, otherwise it will process it according to the recognition result (the recognition result is always one of "UTF-8" and "UTF-16"). Therefore, if the encoding of the XML file is outside of these two types, you must prepend the XML file with an encoding declaration, such as: <?xml version="1.0" encoding="gb2312"?>, it means that the encoding of the XML file is "gb2312".

Most existing XML analyzers do not support Chinese encoding "GB2312" or "BIG5", so XML files containing Chinese cannot be read. You can use analyzers that support Chinese encoding, such as MSXML, IBMJAVA4C, IBMJAVA4J, etc. for XML analysis. You can also use the in-code conversion tool to convert the encoding to "UTF-8" or "UTF-16" and then parse it, and then convert the parsing results back to the original encoding. ccnv (Code Converter) in the software park of this site is such a tool. Of course, you can also write an internal code conversion program yourself.

For detailed information on the encoding of "UTF-8" and "UTF-16", please check the UTF-16 and UTF-8 standards in the collection of standards on this site.

6.How to connect XML to a database?


XML is a file format. It does not specify the connection method to the database. You need to use traditional methods to connect to the database, conduct database queries, and then convert the query results into XML format. Now some tools provide that the XML connection process mostly follows this step. The following is an example of using ASP to directly generate XML files. You can access /Asps/test/ to see the execution effect.
Copy the codeThe code is as follows:
<%@ language="VBScript" %> 
<?xml version="1.0" encoding="gb2312"?> 
<?xml:stylesheet type="text/xsl" href="..image "?> 
<roster> 
<% 
set cConn = ("") 
call ("DSN","USER", "PWD") 
set rs = ("SELECT DISTINCT * FROM roster") 
Do While Not  %> 
<Record> 
<Name><%=trim(rs("name"))%></Name> 
<NativePlace><%=trim(rs("NativePlace"))%></NativePlace> 
<Age><%=trim(rs("Age"))%></Age> 
<Telephone><%=trim(rs("Telephone"))%></Telephone> 
</Record> 
<%  
Loop 
 
set rs=nothing 
set cConn=nothing 
%> 
</roster>