XML 1
About XML 2
XML
XML (ang:eXtensible Markup Language). Just like HTML, XML uses tags ( '<' and '>'),
and attributes (name="value").
Extensible means that it can be customized
to your needs XML document is a text le.
XML was designed to transport the data (not XML Independent of programming language.
the format)
XML is a markup language much like HTML.
3
In XML tags are not prede ned, you can
de ne them yourself.
Tags
<title lang="en">Visuality</title>
<title> - Opening tag
Visuality - Content
lang - Attribute name
"en" - Attribute content 4
</title> - Closing tag
XML Tree Structure
<?xml version="1.0" encoding="UTF-8"?> Hierarchy of the elements
<notes>
<note>
<from>Visuality</from>
<to>Mentor</to>
<body>Do not hit students!!</body>
</note>
<note>
<from>Mentor</from> 5
<to>Students</to>
<body>Hello.</body>
</note>
</notes>
XML Structure
Header: An element can contain:
<?xml version="1.0" encoding="UTF-8"?> text
attributes
The XML header is optional. If it exists, it must
come rst in the document. other elements
XML documents must contain one root element
that is the parent of all other elements. In this 6
example the root element is: <notes>
XML syntax
Rules:
An element name can contain any alphanumeric characters. The only punctuation marks allowed
in names are the hyphen (-), under-score (_) and period (.). Names must begin with a letter
character.
An element, which is a container, can contain text or elements as seen in the above example.
Names are case sensitive. For example, Address, address, and ADDRESS are di erent names.
7
Opening and closing tags of an element must be identical.
XML document validation
The easiest way to check the syntax is to open In case of an error, we will be informed about it:
the xml le in a browser (e.g. Firefox).
8
XML Documents Usage
XML Usage
• XML can be used to exchange the information between organizations and systems.
• Maven uses XML in con g les (settings.xml; pro les.xml; pom.xml).
• XML can be used to store and arrange the data, which can customize your data handling needs.
• XML can easily be merged with style sheets to create almost any desired output.
9
Task
Using any notebook (Notepad, Notepad ++, Sublime Text, etc.) prepare an XML document that will
describe your home library. The bookcase should contain 4 books. Each book should contain the
author (tag: author), title (tag: title) and publication date (tag: year): For example:
• "Refactoring" Martin Fowler, 2016
•
10
"The Phoenix Project" Gene Kim, 2018
• "The Clean Code" Robert C.Martin, 2017
• "Never Split the Di erence", Chris Voss, 2015
Task duration: 15 minutes
JSON 11
JSON 12
JSON
JSON (JavaScript Object Notation) is a simple data exchange format. Storage and retrieval of data in
this format are simple to learn for programmers/testers. At the same time, it is easy to read and
process for computer systems. It's based on JavaScript by de nition. JSON is a text format,
completely independent of programming languages, but it uses the concepts known to
programmers of such languages as C, C++, C#, JAVA, JavaScript, Perl, Python, and many others. Those
properties make JSON the perfect data exchange format.
13
XML / JSON
<?xml version="1.0" encoding="UTF-8"?> {
<notes> "notes": {
<note> "note": [
<from>Visuality</from> {
<to>Mentor</to> "from":"Visuality",
<body>Do not hit students!!</body> "to":"Mentor",
</note> "body":"Do not hit students!",
<note> },
<from>Mentor</from> { 14
<to>Students</to> "from":"Mentor",
<body>Hello.</body> "to":"Students",
</note> "body":"Hello.",
</notes> },
]
}
}
THE END 15
Go to the next presentation