PB138: Introduction to course and XML

Your teacher

software and big data architect

working for some large companies

and also outside IT

developed applications used by hundreds millions of people around the world

My daily bread

.NET: C#, F#

Typescript, React, Node

Python

Rust

Cloud infrastructure

Machine learning systems

DWH solutions

Large frontend & backend systems

About this course

XML

XML

HTML/CSS

APIs

React

Lectures

Seminars

Iterations

Project

Iterations

starting week 3

2 point per 1 iteration, max. 20 in total.

3 weeks to finish the iteration

not possible to start new iteration without previous

Projects

assignments available in week 7

40 points

teams of maximum 4 people (no exceptions)

if less people you still have to do work of 4

team members across seminar groups possible

Now let's peek into software industry

Typical industry positions

DB Engineer

Backend Developer

Frontend Developer

and the almighty mythical Full Stack Developer

Traditional teams had specialist for all positions. That proved to be not ideal.

Not flexible enough, not scalable, poor end product quality

Modern teams have full stack developers who are not afraid using any language, doing backend, frontend, cloud.

They are flexible, thing about product end to end, provide higher value for company

Be open

Breadth knowledge  preferred
Focus on real value

It's always about money

Now today's topic

Where is XML used?

build and configuration (Java&.NET)

data exchange format in legacy services and government

product information exchange, supply chain systems

web scraping

translations

XML document

<?xml version="1.0"?>
<catalog>
   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price>44.95</price>
      <publish_date>2000-10-01</publish_date>
      <description>An in-depth look at creating applications 
      with XML.</description>
   </book>
   <book id="bk102">
      <author>Ralls, Kim</author>
      <title>Midnight Rain</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-12-16</publish_date>
      <description>A former architect battles corporate zombies, 
      an evil sorceress, and her own childhood to become queen 
      of the world.</description>
   </book>
</catalog>

There are some things to remember when constructing a basic XML document.

  • All elements must have an end tag.

  • All elements must be cleanly nested (overlapping elements are not allowed).

  • All attribute values must be enclosed in quotation marks.

  • Each document must have a unique first element, the root node.

All known naming conventions are used across systems

Warning: following slides are drastic

<Data dic_popl="CZ00000019" id_provoz="41" 
id_pokl="33/74# 12" porad_cis="35463"
dat_trzby="2017-10-31T13:15:11+01:00" 
celk_trzba="120.00" zakl_dan2="104.35" 
dan2="15.65"rezim="0" /> 
<Data dic_popl="CZ00000019" id_provoz="41" 
id_pokl="L22T" porad_cis="258143-123"
dat_trzby="2017-04-23T09:45:07+02:00" 
celk_trzba="94.00" zakl_dan2="100.00" 
dan2="15.00" rezim="0" /> 
<are:Ares_odpovedi xmlns:are="http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/ares/ares_answer/v_1.0.1" xmlns:dtt="http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/ares/ares_datatypes/v_1.0.4" xmlns:udt="http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/uvis_datatypes/v_1.0.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" odpoved_datum_cas="2021-03-04T12:41:18" odpoved_pocet="1" odpoved_typ="Standard" vystup_format="XML" xslt="klient" validation_XSLT="/ares/xml_doc/schemas/ares/ares_answer/v_1.0.0/ares_answer.xsl" xsi:schemaLocation="http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/ares/ares_answer/v_1.0.1 http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/ares/ares_answer/v_1.0.1/ares_answer_v_1.0.1.xsd" Id="ares">
    <are:Odpoved>
        <are:Pocet_zaznamu>1</are:Pocet_zaznamu>
        <are:Typ_vyhledani>FREE</are:Typ_vyhledani>
        <are:Zaznam>
            <are:Shoda_ICO>
                <dtt:Kod>9</dtt:Kod>
            </are:Shoda_ICO>
            <are:Vyhledano_dle>ICO</are:Vyhledano_dle>
            <are:Typ_registru>
                <dtt:Kod>2</dtt:Kod>
                <dtt:Text>OR</dtt:Text>
            </are:Typ_registru>
            <are:Datum_vzniku>2003-08-06</are:Datum_vzniku>
            <are:Datum_platnosti>2021-03-04</are:Datum_platnosti>
            <are:Pravni_forma>
                <dtt:Kod_PF>121</dtt:Kod_PF>
            </are:Pravni_forma>
            <are:Obchodni_firma>Asseco Central Europe, a.s.</are:Obchodni_firma>
            <are:ICO>27074358</are:ICO>
            <are:Identifikace>
                <are:Adresa_ARES>
                    <dtt:ID_adresy>210432740</dtt:ID_adresy>
                    <dtt:Kod_statu>203</dtt:Kod_statu>
                    <dtt:Nazev_okresu>Hlavní město Praha</dtt:Nazev_okresu>
                    <dtt:Nazev_ulice>Budějovická</dtt:Nazev_ulice>
                    <dtt:Cislo_domovni>778</dtt:Cislo_domovni>
                    <dtt:Typ_cislo_domovni>1</dtt:Typ_cislo_domovni>
                    <dtt:Cislo_orientacni>3a</dtt:Cislo_orientacni>
                    <dtt:PSC>14000</dtt:PSC>
                    <dtt:Adresa_UIR>
                        <udt:Kod_oblasti>19</udt:Kod_oblasti>
                        <udt:Kod_kraje>19</udt:Kod_kraje>
                        <udt:Kod_okresu>3100</udt:Kod_okresu>
                        <udt:Kod_obce>554782</udt:Kod_obce>
                        <udt:Kod_pobvod>43</udt:Kod_pobvod>
                        <udt:Kod_nobvod>43</udt:Kod_nobvod>
                        <udt:Pism_cislo_orientacni>a</udt:Pism_cislo_orientacni>
                        <udt:Kod_adresy>41405609</udt:Kod_adresy>
                        <udt:Kod_objektu>21770794</udt:Kod_objektu>
                    </dtt:Adresa_UIR>
                </are:Adresa_ARES>
            </are:Identifikace>
            <are:Kod_FU>4</are:Kod_FU>
            <are:Priznaky_subjektu>NAAANANNNNANNNNNNNNNNNNNANNNNN</are:Priznaky_subjektu>
        </are:Zaznam>
    </are:Odpoved>
</are:Ares_odpovedi>

That's it for XML

XML Schema

An XML Schema describes the structure of an XML document.

The XML Schema language is also referred to as XML Schema Definition (XSD).

XML Schema

The purpose of an XML Schema is to define the legal building blocks of an XML document:

  • the elements and attributes that can appear in a document
  • the number of (and order of) child elements
  • data types for elements and attributes
  • default and fixed values for elements and attributes
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
 
<xs:element name="note">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="to" type="xs:string"/>
      <xs:element name="from" type="xs:string"/>
      <xs:element name="heading" type="xs:string"/>
      <xs:element name="body" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>
 
</xs:schema>

Start with basic structure

<?xml version="1.0"?>

<xs:schema>
...
...
</xs:schema>

You can define element

A simple element is an XML element that can contain only text. It cannot contain any other elements or attributes.

 

<xs:element name="xxx" type="yyy"/>

Types

xs:string
xs:decimal
xs:integer
xs:boolean
xs:date
xs:time

Attributes

<xs:attribute name="lang" type="xs:string" default="EN"/>

can have also default value

<xs:attribute name="lang" type="xs:string" use="required"/>

and can be marked as required

Restrictions on value

<xs:element name="age">
  <xs:simpleType>
    <xs:restriction base="xs:integer">
      <xs:minInclusive value="0"/>
      <xs:maxInclusive value="120"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>
<xs:element name="employee" type="personinfo"/>
<xs:element name="student" type="personinfo"/>
<xs:element name="member" type="personinfo"/>

<xs:complexType name="personinfo">
  <xs:sequence>
    <xs:element name="firstname" type="xs:string"/>
    <xs:element name="lastname" type="xs:string"/>
  </xs:sequence>
</xs:complexType>

Complex type

first approach

Complex type

<xs:element name="employee">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="firstname" type="xs:string"/>
      <xs:element name="lastname" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

second approach

Restrictions as enum

<xs:element name="car" type="carType"/>

<xs:simpleType name="carType">
  <xs:restriction base="xs:string">
    <xs:enumeration value="Audi"/>
    <xs:enumeration value="Golf"/>
    <xs:enumeration value="BMW"/>
  </xs:restriction>
</xs:simpleType>

Limit occurrences of element

<xs:element name="employee" maxOccurs="unbounded">
  ...
</xs:element>

Enough for today

Next week:

Relation schema design (and ERD)

Modeling XML based on schema

XPath

PB138: Introduction to course and XML

By Lukáš Grolig

PB138: Introduction to course and XML

  • 386