XML simple knowledge

xml (EXtensible Markup L anguage) Extensible Markup Language

  • < span style="font-size: 16px;">The first line must be an xml statement: Example: hr.xml
  • The handling of special characters:

1. Use entity references

share picture

2. Use CDATA tags p>

CDATA is text data that should not be parsed by an XML parser

The CDATA part starts with “” and starts with “ ]]>” End

  • xml semantic constraints

1. DTD (Document Type Definition: Document Type Definition) .dtd Example: hr.dtd

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

DOCTYPE hr SYSTEM "hr.dtd">

<hr >
<employee no="3301">
<name >Li Tiezhuname>
<age >37age>
<salary >3600salary>
<department >
<dname >Personnel Departmentdname>
<address >XX Building-B105address>
department>
employee>
<employee no="3302">
<name >Lin Hainame>
<age >50age>
<salary >7000salary>
<department >
<dname >Finance Departmentdname>
<address >XX Building-B106address>
department>
employee>
hr>














2.XML Schema Currently using more .xsd Example: hr.xsd

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

<schema xmlns="http://www.w3.org/2001/XMLSchema">
<element name="hr">

<complexType >
<sequence >
 
 <element name="employee" minOccurs="1" maxOccurs="9999">

<complexType >
<sequence >
<element name="name" type="string">element>
<element name="age">
<simpleType >
<restriction base="integer">
<minInclusive value="18">minInclusive>
<maxInclusive value="60">maxInclusive>
restriction>
simpleType>
element>
<element name="salary" type="integer">element>
<element name="department">
<complexType >
<sequence >
<element name="dname" type="string">element>
<element name="address" type="string">element>
sequence>
complexType>
element>
sequence>
<attribute name="no" type="string" use="required"< span style="color: #0000ff;">>attribute> span>
complexType>
element>
sequence>
complexType>
element>
schema>

<< span style="color: #800000;">hr xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"

xsi:noNamespaceSchemaLocation
="hr.xsd">

Second part: JAVA operation XML document

Learn from: https://class.imooc.com/course/714

p>

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

DOCTYPE hr SYSTEM "hr.dtd">

<hr >
<employee no="3301">
<name >Li Tiezhuname>
<age >37age>
<salary >3600salary>
<department >
<dname >Personnel Departmentdname>
<address >XX Building-B105address>
department>
employee>
<employee no="3302">
<name >Lin Hainame>
<age >50age>
<salary >7000salary>
<department >
<dname >Finance Departmentdname>
<address >XX Building-B106address>
department>
employee>
hr>



(employee+): At least 1 employee node is allowed
(employee*): 0 to n employee nodes are allowed
(employee?): At most An employee node appears
-->





<complexType >
<sequence >
 
 <element name="employee" minOccurs="1" maxOccurs="9999">

<complexType >
<sequence >
<element name="name" type="string">element>
<element name="age">
<simpleType >
<restriction base="integer">
<minInclusive value="18">minInclusive>
<maxInclusive value="60">maxInclusive>
restriction>
simpleType>
element>
<element name="salary" type="integer">element>
<element name="department">
<complexType >
<sequence >
<element name="dname" type="string">element>
<element name="address" type="string">element>
sequence>
complexType>
element>
sequence>
<attribute name="no" type="string" use="required"< span style="color: #0000ff;">>attribute> span>
complexType>
element>
sequence>
complexType>
element>
schema>

<hr xmlns:xsi="http://www.w3.org/2001/XMLSchema -instance"

xsi:noNamespaceSchemaLocation
="hr.xsd">

Leave a Comment

Your email address will not be published.