6.42.1. What is XML? #
XML refers to Extensible markup language.
Extensible markup language, a subset of the standard generic markup language, a markup language for tagging electronic documents to make them structural.
It can be used to mark data and define data types. It is a source language that allows users to define their own markup language. It is ideal for Worldwide Web transmission and provides a unified way to describe and exchange structured data independent of applications or vendors.
For more information, please see our XML tutorial.
6.42.2. XML parser structure and API #
The main parsers for XML are DOM and SAX.
The SAX parser is event-based and needs to scan the XML document from beginning to end. In the scanning process, each time a syntax structure is encountered, the event handler of this particular syntax structure is calledto send an event to the application.
DOM is the parsing of the document object model, the hierarchical syntax structure of the document is built, and the DOM tree is established in memory. The nodes of the DOM tree are identified in the form of objects. After the document parsing is completed, the entire DOM tree of the documentwill be placed in memory.
6.42.3. Parsing and creating XML in Ruby #
This library REXML library can be used for parsing XML documents in RUBY.
The REXML library is an XML toolkit for Ruby, written in the pure Ruby language and compliant with the XML 1.0 specification.
In Ruby version 1.8 and beyond, REXML will be included in the RUBY standard library.
The path to the REXML library is: rexml/document
All methods and classes are encapsulated in a REXML module.
REXML parsers have the following advantages over other parsers:
100% written by Ruby.
Applicable to SAX and DOM parsers.
It’s lightweight, less than 2000 lines of code.
Methods and classes that are easy to understand.
Based on SAX2 API and full XPath support.
Install using Ruby instead of a separate installation.
The following is the XML code for the example, saved as movies.xml :
War, Thriller DVD 2003 PG 10 Talk about a US-Japan war Anime, Science Fiction DVD 1989 R 8 A schientific fiction Anime, Action DVD 4 PG 10 Vash the Stampede! Comedy VHS PG 2 Viewable boredom 6.42.4. DOM parser #
Let’s parse the XML data first. First, let’s introduce the rexml/document library. Usually we can introduce REXML in the top-level namespace:
Example #
#!/usr/bin/ruby -wrequire'rexml/document'includeREXMLxmlfile=File.new("movies.xml")xmldoc=Document.new(xmlfile)#obtain root element root=xmldoc.rootputs"Root element :"+root.attributes["shelf"]#The following will output the movie title xmldoc.elements.each("collection/movie"){ \|e\|puts"Movie Title :"+e.attributes["title"]}#The following will output all movie types xmldoc.elements.each("collection/movie/type"){ \|e\|puts"Movie Type :"+e.text}#The following will output all movie descriptions xmldoc.elements.each("collection/movie/description"){ \|e\|puts"Movie Description :"+e.text}
The output result of the above example is:
Root element : New Arrivals Movie Title : Enemy Behind Movie Title : Transformers Movie Title : Trigun Movie Title : Ishtar Movie Type : War, Thriller Movie Type : Anime, Science Fiction Movie Type : Anime, Action Movie Type : Comedy Movie Description : Talk about a US-Japan war Movie Description : A schientific fiction Movie Description : Vash the Stampede! Movie Description : Viewable boredom SAX-like Parsing:
6.42.5. SAX parser #
Deal with the same data file: accounes.xml` . It is not recommended to resolve SAX to a small file. Here is a simple example:
Example #
#!/usr/bin/ruby -wrequire'rexml/document'require'rexml/streamlistener'includeREXMLclassMyListenerincludeREXML::StreamListenerdeftag_start(*args)puts"tag_start: #{args.map {|x\| x.inspect}.join(', ')}"enddeftext(data)returnifdata=~/^\\w*$/#whitespace onlyabbrev=data[0..40]+(data.length>40?"...":"")puts"text : #{abbrev.inspect}"endendlist=MyListener.newxmlfile=File.new("movies.xml")Document.parse_stream(xmlfile,list) The above output is as follows:
tag_start: "collection", {"shelf"=>"New Arrivals"} tag_start: "movie", {"title"=>"Enemy Behind"} tag_start: "type", {} text : "War, Thriller" tag_start: "format", {} tag_start: "year", {} tag_start: "rating", {} tag_start: "stars", {} tag_start: "description", {} text : "Talk about a US-Japan war" tag_start: "movie", {"title"=>"Transformers"} tag_start: "type", {} text : "Anime, Science Fiction" tag_start: "format", {} tag_start: "year", {} tag_start: "rating", {} tag_start: "stars", {} tag_start: "description", {} text : "A schientific fiction" tag_start: "movie", {"title"=>"Trigun"} tag_start: "type", {} text : "Anime, Action" tag_start: "format", {} tag_start: "episodes", {} tag_start: "rating", {} tag_start: "stars", {} tag_start: "description", {} text : "Vash the Stampede!" tag_start: "movie", {"title"=>"Ishtar"} tag_start: "type", {} tag_start: "format", {} tag_start: "rating", {} tag_start: "stars", {} tag_start: "description", {} text : "Viewable boredom"
6.42.6. XPath and Ruby #
We can use XPath to view XML, a language for finding information in XML documents (see: XPath tutorial).
XPath is the XML path language, which is a language used to determine the location of a part of an XML (a subset of the standard general markup language) document. XPath is based on the tree structure of XML and providesthe ability to find nodes in the data structure tree.
Ruby supports XPath through REXML’s XPath class, which is a tree-based analysis (document object model).
Example #
#!/usr/bin/ruby -wrequire'rexml/document'includeREXMLxmlfile=File.new("movies.xml")xmldoc=Document.new(xmlfile)# Information about the first movie movie=XPath.first(xmldoc,"//movie")pmovie#Print all movie types XPath.each(xmldoc,"//type"){ \|e\|putse.text}#Obtain the types of all movie formats and return an array names=XPath.match(xmldoc,"//format").map{\|x\|x.text}pnames
The output result of the above example is:
<movie title='Enemy Behind'> ... War, Thriller Anime, Science Fiction Anime, Action Comedy ["DVD", "DVD", "DVD", "VHS"]
6.42.7. XSLT and Ruby #
There are two XSLT parsers in Ruby, which are briefly described below:
6.42.8. Ruby-Sablotron #
This parser is created by Justice Masayoshi Takahash write and maintain. This is mainly written for the Linux operating system and requiresthe following libraries:
-
Sablot
-
Iconv
-
Expat
You can do it in the Ruby-Sablotron Find these libraries.
6.42.9. XSLT4R #
XSLT4R is written by Michael Neumann. XSLT4R is used for simple command-line interaction and can be used by third-party applications to transform XML documents.
-
1. Angularjs2
8
-
1. SVG tutorial
19
-
1. Memcached
20
-
1. C# tutorial
61
-
1. Sqlite
47
-
2. Go
43
-
2. Docker
59
-
2. Vue3
19
-
2. Servlet
21
-
3. React
23
-
3. SOAP tutorial
10
-
3. Android
18
-
3. Mongodb
44
-
3. Kotlin
18
-
4. Lua
31
-
4. MySQL tutorial
35
-
4. Appml
12
-
5. Perl
45
-
5. Postgresql
41
-
web
15
-
5. Web Services tutorial
6
-
6. Ruby
42
-
6.12. Ruby class case
-
6.8. Ruby environment variable
-
6.34. Ruby DBI Read operation
-
6.7. Ruby command line options
-
6.39. Ruby CGI Session
-
6.10. Ruby data type
-
6.35. Ruby connection Mysql-MySql2
-
6.9. Ruby syntax
-
6.24. Ruby date & time
-
6.31. Ruby object oriented
-
6. Design-pattern
35
-
7. Django
18
-
7. Rust
22
-
6. WSDL tutorial
8
-
8. Foundation
39
-
9. Ios
43
-
8. Css3
26
-
9. Swift
44
-
11. HTML tutorial-(HTML5 Standard)
54
-
12. Http
6
-
13. Regex
6
-
14. Regexp
8
《地理信息系统原理、技术与方法》
97
最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。
-
1. Introduction to geographic information system
6
-
2. From the Real World to the Bit World
3
-
3. Spatial Data Model
7
-
4. 空间参照系统和 地图投影
5
-
5. Data in GIS
3
-
6. Spatial data acquisition
2
-
7. Spatial Data Management
6
-
8. Spatial analysis
8
-
9. 数字地形模型( DTM )与地形分析
5
-
10. 空间建模与 空间决策支持
6
-
11. Spatial data representation and map making
6
-
12. 3S Integration Technology
5
-
13. 网络地理信息系统
3
-
14. Examples of Geographic Information System Application
8
-
15. Organization and Management of Geographic Information System Application Projects
9
-
16. Geographic Information system Software Engineering Technology
6
-
17. Geographic Information System Standards
3
-
18. Geographic Information System and Society
3
-
19. Earth Information Science and Digital Earth
3