Skip to content

Commit 46a3dba

Browse files
authored
feat(xml)
1 parent af3fc0a commit 46a3dba

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

2.3_maven-junit/xml.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# XML
2+
3+
XML расшифровывается как eXtensible Markup Language (расширяемый язык разметки) - специальный язык, созданный для обмена структурированной информацией.
4+
5+
В нашем с вами случае, мы чаще всего будем встречаться с ним в виде файла `pom.xml`, в котором описана объектная модель нашего Maven проекта.
6+
7+
XML документ начинается с объявления, которое выглядит следующим образом:
8+
```xml
9+
<?xml version="1.0" encoding="UTF-8"?>
10+
```
11+
12+
Это означает, что наш документ использует стандарт 1.0 и написан в кодировке UTF-8.
13+
14+
Далее документ состоит из тегов.
15+
16+
Тег - это специальный структурный элемент, который состоит из 4 частей:
17+
1. Открывающий тег `<project>`
18+
1. Закрывающий тег `</project>`
19+
1. Атрибуты (пишутся только в открывающем теге): `<project attribute="value">`, при этом значения пишутся в кавычках
20+
1. Содержимого (пишется между открывающим и закрывающим тегом)
21+
22+
Возникает ключевой вопрос: откуда берутся теги, атрибуты и т.д.? Где это написано?
23+
24+
На самом деле, к xml-документу обычно идёт XSD (Xml Schema Definition), она и определяет правила:
25+
- какие теги можно использовать
26+
- какие атрибуты есть у тегов
27+
- какие теги какое содержимое могут иметь
28+
29+
Для Maven схема располагается по адресу: http://maven.apache.org/xsd/maven-4.0.0.xsd
30+
31+
И для тега `project` там написано следующее:
32+
```xml
33+
<xs:element name="project" type="Model">
34+
<xs:annotation>
35+
<xs:documentation source="version">3.0.0+</xs:documentation>
36+
<xs:documentation source="description">
37+
The <code>&lt;project&gt;</code> element is the root of the descriptor. The following table lists all of the possible child elements.
38+
</xs:documentation>
39+
</xs:annotation>
40+
</xs:element>
41+
```
42+
43+
Далее описан тип `Model`:
44+
```xml
45+
<xs:complexType name="Model">
46+
<xs:annotation>
47+
<xs:documentation source="version">3.0.0+</xs:documentation>
48+
<xs:documentation source="description">
49+
The <code>&lt;project&gt;</code> element is the root of the descriptor. The following table lists all of the possible child elements.
50+
</xs:documentation>
51+
</xs:annotation>
52+
<xs:all>
53+
<xs:element minOccurs="0" name="modelVersion" type="xs:string">
54+
<xs:annotation>
55+
<xs:documentation source="version">4.0.0+</xs:documentation>
56+
<xs:documentation source="description">
57+
Declares to which version of project descriptor this POM conforms.
58+
</xs:documentation>
59+
</xs:annotation>
60+
</xs:element>
61+
...
62+
<xs:element minOccurs="0" name="groupId" type="xs:string">
63+
<xs:annotation>
64+
<xs:documentation source="version">3.0.0+</xs:documentation>
65+
<xs:documentation source="description">
66+
A universally unique identifier for a project. It is normal to use a fully-qualified package name to distinguish it from other projects with a similar name (eg. <code>org.apache.maven</code>).
67+
</xs:documentation>
68+
</xs:annotation>
69+
</xs:element>
70+
<xs:element minOccurs="0" name="artifactId" type="xs:string">
71+
<xs:annotation>
72+
<xs:documentation source="version">3.0.0+</xs:documentation>
73+
<xs:documentation source="description">
74+
The identifier for this artifact that is unique within the group given by the group ID. An artifact is something that is either produced or used by a project. Examples of artifacts produced by Maven for a project include: JARs, source and binary distributions, and WARs.
75+
</xs:documentation>
76+
</xs:annotation>
77+
</xs:element>
78+
<xs:element minOccurs="0" name="version" type="xs:string">
79+
<xs:annotation>
80+
<xs:documentation source="version">4.0.0+</xs:documentation>
81+
<xs:documentation source="description">
82+
The current version of the artifact produced by this project.
83+
</xs:documentation>
84+
</xs:annotation>
85+
</xs:element>
86+
...
87+
</xs:complexType>
88+
```
89+
90+
Что это значит для нас?
91+
1. Неплохо бы приучить себя читать такие определения (т.к. именно в них написано, что, для чего и как)
92+
1. Нельзя просто так взять, скопировать "кусок xml" и подставить куда угодно (т.к. правилами жёстко регламентируется, что, куда и когда можно подставлять)
93+
94+
Поэтому внимательно относитесь к тому, как именно вы оформляете xml-документ (следите за тем, чтобы это было сделано так же, как в лекции).

0 commit comments

Comments
 (0)