6. Java basic I/O 5. Java and XML

Содержание

Слайд 2

Why XML? XML is a very useful technology for describing structured

Why XML?

XML is a very useful technology for describing structured information
XML

tools make it easy to process and transform information
XML has employed as the base language for communication protocols
XML is widely used as protocol language in Java EE APIs

*

Infopulse Training Center

Слайд 3

XML Example 4.0.0 webapp.sample web-parent 1.0-SNAPSHOT web-app jar Web Demo -

XML Example



  4.0.0


  webapp.sample
  web-parent
  1.0-SNAPSHOT
 

  web-app
  jar
  Web Demo - Application UI project

*

Infopulse Training Center

Слайд 4

What is an XML? Extensible Markup Language (XML) is a markup

What is an XML?

Extensible Markup Language (XML) is a markup language

that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable
It is a textual data format with strong support documents structure along with arbitrary data structures

*

Infopulse Training Center

Слайд 5

The Structure of an XML Document An XML document should start

The Structure of an XML Document

An XML document should start with

a header such as or
A header is optional, but it is highly recommended
The body of the XML document contains the root element (only one!), which can contain other elements (child elements)

*

Infopulse Training Center

Слайд 6

XML Example 4.0.0 webapp.sample web-parent 1.0-SNAPSHOT web-app jar Web Demo -

XML Example



  4.0.0


  webapp.sample
  web-parent
  1.0-SNAPSHOT
 

  web-app
  jar
  Web Demo - Application UI project

*

Infopulse Training Center

Слайд 7

Element A logical document component either begins with a start-tag and

Element

A logical document component either begins with a start-tag and ends

with a matching end-tag or consists only of an empty-element tag: 4.0.0

*

Infopulse Training Center

Слайд 8

Element (continued) An element can contain child elements, text, or both:

Element (continued)

An element can contain child elements, text, or both:

  webapp.sample


  web-parent
  1.0-SNAPSHOT
 

*

Infopulse Training Center

Слайд 9

Attributes A markup construct consisting of a name/value pair that exists

Attributes

A markup construct consisting of a name/value pair that exists within

a start-tag or empty-element tag:

*

Infopulse Training Center

Слайд 10

Parsing an XML Document To process an XML document, you need

Parsing an XML Document

To process an XML document, you need to

parse it:
read a file
confirm that the file has the correct format
break it up into the constituent elements
access those elements

*

Infopulse Training Center

Слайд 11

Java XML Parsers Tree parser - Document Object Model (DOM) that

Java XML Parsers

Tree parser - Document Object Model (DOM) that read

an XML document into a tree structure.
Streaming parser - Simple API for XML (SAX) that generate events as they read an XML document.

*

Infopulse Training Center

Слайд 12

XML namespace XML namespaces are used for providing uniquely named elements

XML namespace

XML namespaces are used for providing uniquely named elements and

attributes in an XML document
A namespace name is a uniform resource identifier (URI)
Typically, the URI chosen for the namespace of a given XML vocabulary describes a resource under the control of the author or organization defining the vocabulary

*

Infopulse Training Center

Слайд 13

Namespace declaration An XML namespace is declared using the reserved XML

Namespace declaration

An XML namespace is declared using the reserved XML attribute

xmlns or xmlns:prefix, the value of which must be a valid namespace name:
xmlns:xhtml="http://www.w3.org/1999/xhtml"
Any element or attribute whose name starts with the prefix "xhtml:" is considered to be in the XHTML namespace

*

Infopulse Training Center

Слайд 14

Default Namespace It is also possible to declare a default namespace:

Default Namespace

It is also possible to declare a default namespace:
xmlns="http://www.w3.org/1999/xhtml"
In

this case, any element without a namespace prefix is considered to be in the XHTML namespace, if it or an ancestor has the above default namespace declaration
Attributes are never subject to the default namespace

*

Infopulse Training Center

Слайд 15

Well-formed XML document Well-formed = correct syntax The begin, end, and

Well-formed XML document

Well-formed = correct syntax
The begin, end, and empty-element tags

that delimit the elements are correctly nested, with none missing and none overlapping.
The element tags are case-sensitive; the beginning and end tags must match exactly.
There is a single "root" element that contains all the other elements

*

Infopulse Training Center

Слайд 16

Valid XML Document Valid = well-formed + semantic-correct Semantic is described

Valid XML Document

Valid = well-formed + semantic-correct
Semantic is described with:
Document Type

Definition (DTD) or
XML Schema definition (XSD)
Contains rules that explain how a document should be formed, by specifying the legal child elements and attributes for each element

*

Infopulse Training Center