XML language

1.1 Introduction to xml

  • a) xml, eXtensible Markup Language, is a markup language.
  • b) xml is a A very flexible language, no fixed tags, all tags can be customized.
  • c) Usually, xml is used for information recording and transmission. Therefore, xml is often used as a configuration file .

1.2 Well-formed xml

  • a) Declaration information, used to describe the version and encoding of xml
  • b) xml has one and only one root element
  • c) xml is case sensitive
  • d) tag They are in pairs, and they must be nested correctly.
  • e) Use double quotes for attribute values

For example:

xml version="1.0" encoding="UTF-8" ?>


<books >
<book id="b01">
<name >java advanced programmingname>
<author >Zhang Sanauthor>
<price >50.5price>
book>
<book id="b02">
<name >java intermediate programmingname>
<author >Li Siauthor>
<price >30.5price>
book>
books>

2. DTD
  2.1 Introduction to DTD
    a) DTD, Document Type Definition, Document Type Definition
    b) DTD is used to constrain xml The document format of xml is guaranteed to be a valid xml.
    c) DTD can be divided into two types, internal DTD, external DTD
2.2 Use DTD 2.2.1 Definition of internal DTD

a ) The syntax is as follows:
   b) Element declaration syntax:
   c) Quantifier
> +: means one or more occurrences, at least once
  > ?: means 0 or 1 occurrence
  > *: means any number of occurrences
d) Attribute declaration syntax:
  > Attribute Type: CDATA, character data (character data)
  > Default value:
  - #REQUIRED, which means must appear
  - #IMPLIED, which means it is not necessary
  
e) Complete xml code with DTD:

< span style="color: #ff00ff;">xml version="1.0" encoding="UTF-8"?>

DOCTYPE scores [>
ELEMENT student (name, course, score)>
ATTLIST student id CDATA #REQUIRED>
ELEMENT name (#PCDATA)>
ELEMENT course (#PCDATA)>
ELEMENT score (#PCDATA)> ]>
<scores>
<student id="1">
<name >Wang Tongname>
<course >javacourse>
<score >89score>
student>
<student id="2">
<name >Li Jianame>
<course >sqlcourse>
<score >58score>
student>
scores>

2.2.2 Definition of external DTD
a) Create an independent dtd file

 xml version="1.0" encoding="UTF-8"?>

ELEMENT scores (student+)>
ELEMENT student (name, course, score)>
ATTLIST student id CDATA #REQUIRED>
ELEMENT name (#PCDATA)>
ELEMENT course (#PCDATA)>
ELEMENT score (#PCDATA)>

b) Import external DTD files in xml



<books >
<book id="b01">
<name >java advanced programmingname>
<author >Zhang Sanauthor>
<price >50.5price>
book>
<book id="b02">
<name >java intermediate programmingname>
<author >Li Siauthor>
<price >30.5price>
book>
books>

 xml version="1.0" encoding="UTF-8"?>

DOCTYPE scores [>
ELEMENT student (name, course, score)>
ATTLIST student id CDATA #REQUIRED>
ELEMENT name (#PCDATA)>
ELEMENT course (#PCDATA)>
ELEMENT score (#PCDATA)> ]>
<scores>
<student id="1">
<name >Wang Tongname>
<course >javacourse>
<score >89score>
student>
<student id="2">
<name >Li Jianame>
<course >sqlcourse>
<score >58score>
student>
scores>

 xml version="1.0" encoding="UTF-8"?>

ELEMENT scores (student+)>
ELEMENT student (name, course, score)>
ATTLIST student id CDATA #REQUIRED>
ELEMENT name (#PCDATA)>
ELEMENT course (#PCDATA)>
ELEMENT score (#PCDATA)>



DOCTYPE scores SYSTEM "scores.dtd">

Leave a Comment

Your email address will not be published.