java learning and application (4.3.1) - XML and analysis

XML

XML (extensible markup language Extensible Markup Language), proposed by the World Wide Web Consortium (W3C), to replace HTML, the basic language and later stored data (configuration files, network file transfer)
the first line of the document declared:? <Xml version = '1.0 ? '> (list of attributes such as version [Required], encoding [default iso-8859-1], standalone [independent of whether the file, has expired]), <? xml-stylesheet tpye = "text / css" href = "xxx .css "?> to get up early and css styles with control display page.
Then custom document labels, and only one with quotation marks with tag, attribute values, labels must be properly closed (or self-closing and paired), and is case sensitive. The only required id tag, CDATA content area as it is demonstrated (<[data DATA [as is shown]]!>) (For special characters)
constraint: documentation writing rules specified xml document, as users of the frame, in xml the introduction of constraint document (DTD, Schema).
DTD: <! ELEMENT> tag defined, the tags added as a child allowed to * as can occur numerous times within parentheses, + is one or more, # PCDATA string. <! ATTLIST> tag has attributes defined sequentially for the tags, attributes, attribute types are (#REQUIRED as must appear).
DTD external dtd, sub-local (<! DOCTYPE root tag name SYSTEM "dtd position">) and a network (<! DOCTYPE root tag name PUBLIC "dtd file name", "location URL">). Also in the internal dtd xml (<! DOCTYPE root tag name [dtd Content]> ).
Schemla constraint: string content can define constraints, xsd extension. Adding methods: introducing the attribute xsi prefix root tag introduced xsd namespace file for each constraint specifies a prefix to simplify xsd namespace, the xmlns of GAP default null prefix.

<?xml version="1.0" encoding="UTF-8" ?>
<!-- 
	1. Fill out the root element of the xml document
	2. Introduction xsi prefix xmlns:. Xsi = "http://www.w3.org/2001/XMLSchema-instance"
	3. The introduction of xsd file namespace xsi:. SchemaLocation = "http://www.itcast.cn/xml student.xsd"
	4. Each xsd constraint specifies a prefix, as the identification xmlns = "http://www.itcast.cn/xml" 
	
	
 -->
<students   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
			xmlns="http://www.itcast.cn/xml"
			xsi:schemaLocation="http://www.itcast.cn/xml  student.xsd"
>
	<student number="heima_0001">
		<name>tom</name>
		<age>18</age>
		<sex>male</sex>
	</student>

</students>

 

XML parsing

XML parsing: DOM parse (server), in accordance CRUD operations dom tree, easy to operate but the total memory. SAX parse (mobile terminal), read line by line, based on event-driven, not of memory, but can only be read.
Parser: JAXP support provided by the sun's dom and sax, DOM4J relatively good parser. Html parsing Jsoup etc. [example], PULL parser is built Android. Jar package import, acquisition Document object, Element object, retrieving the data.
Jsoup use code, see Demo1.
Jsoup tool objects parsed html (parse incoming file and encoded data string or URL or network resource objects and to load the timeout dom),
the Document object represents dom tree (tag id attribute acquiring Elements other elements of the set to obtain the object based on [the ArrayList] ), elements representative of element object set,
element element object (comprising obtaining sub-label getElement the like, attr getting a property value according to the attribute name, text acquired text, html acquires the content tag body), node node object (parent Document and element of class objects).
Quick and easy way: selector selector, reference Select class methods defined. document.select method for obtaining the attribute value matching element and the data for selected attributes, add an escape within quotation marks in parenthesis,> its child tag.
XPath: Import jar package, get Document object, creating JXDocument object, use JXDocument the syntax of the query, the query method as selN method write path expressions (see manual).

 

Guess you like

Origin www.cnblogs.com/bai2018/p/12306934.html