Dark Horse's fifth day of Sax parsing XML documents and Dom4J parsing XML documents

Source: Internet
Author: User

Measure the test taker's knowledge about Dom4J parsing and Xpath writing.

Dom4J Quick Start

I. Using JAXP for SAX parsing (the logic is a little difficult)
1. SAX can only read documents
2,
<? Xml version = "1.0" encoding = "UTF-8" standalone = "no"?> // Start of the document
<Bookshelves> // start element // text
<Book Publishing House = "" No. = "A1"> // start with the element
<Title> Java employment training course </title>
<Author> Zhang Xiaoxiang </author>
<Price> 29 RMB </price>
<Wholesale price> 100 </wholesale price>
</Book>
<Book Publishing House = "Chuanzhi podcast" No. = "A2">
<Title> JavaScript web development </title>
<Author> Yu Yang </author>
<Price> 28.00 RMB </price>
</Book>
</Bookshelves> // element end
 
// End the document
 
Ii. JUnit unit test
3. Basic Dom4J exercises
4. Xpath: Find some/element or attribute

5. Use Dom4J to rewrite Small scores
6. Schema constraints (understand Schema, with emphasis on introducing Schema constraints in xml)
Namespace:
Html: table
Life: table

Com. itheima. a. A. class
Com. itheima. B. A. class
1. How to introduce schema constraints in xml
A. view the schema document and find the root element.
<? Xml version = "1.0" encoding = "UTF-8"?>
<Bookshelves>

</Bookshelves>
B. Which namespace does the bookshelf come from? View the schema document (because each schema document is bound to a namespace)
Introduce to our XML file
<? Xml version = "1.0" encoding = "UTF-8"?>
<Itheima: bookshelves xmlns: itheima = "http://www.itheima.com">

</Itheima: bookshelf>
C. Which xsd file does the namespace correspond? Specify the relationship between the two using schemaLocation
<? Xml version = "1.0" encoding = "UTF-8"?>
<Itheima: bookshelves xmlns: itheima = "http://www.itheima.com"
SchemaLocation = "http://www.itheima.com book. xsd">

</Itheima: bookshelf>
D. Which namespace does schemaLocation come from? From a standard namespace http://www.w3.org/2001/XMLSchema-instance

<? Xml version = "1.0" encoding = "UTF-8"?>
<Itheima: bookshelves xmlns: itheima = "http://www.itheima.com"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xsi: schemaLocation = "http://www.itheima.com book. xsd">

</Itheima: bookshelf>

 

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.