It is important to learn XML

XML in 5 minutes: what is it? Easily explained

2

<Erklärung>XML</Erklärung>

Today is about a technology that you use every day when you work on the computer. You can now find out what XML is and why these angle brackets are not a secret language.

What is XML

XML is the abbreviation for Extensible Markup Language. It is a text-based data format, like JSON.

This means that the data can be edited in a text editor and computers can read and write this format.

The advantage of XML lies in the first word extensible. This language is extensible and used in technologies you use every day these days.

That includes HTML, RSS, SVG and many more, but we'll get to that in a moment.

Real world example: How does XML work?

Let's do a little exercise to understand how XML actually works. You will receive a slip of paper with the following information.

There's not much you can do with the information itself. I will give you the task of drawing a small drawing on a piece of paper and paying attention to all the elements that are on the piece of paper.

Pay attention to the additional information and elements that are IN other elements. So grab a piece of paper, pause the video and off you go.
Does your result look something like this? Very good.

If not, then there were some elements that were not entirely clear. This is because you did not know the format used. A computer would not have been able to do anything with this information and without additional programming. For this reason we will now describe our elements in the drawing using XML.

How is XML structured?

The drawing itself would also appear as an element in the XML. In XML, the elements and child elements are marked with start and end points. The information about the house in our drawing would look like this in XML. Brief explanation about this:

To mark the beginning of the element, put it in angle brackets. An additional slash is inserted at the end of an element. If an element has no further content, you can omit the end element and insert the slash directly at the rear bracket.

This means that these elements can be seen better on the drawing. For the drawing element, we also have additional information called attributes. Attributes are always given a name and then assigned a value with an equal sign. This value is set in apostrophes. We have the page format attribute with the value DIN A4 and the alignment attribute with the value landscape. Text can be written into the elements or additional elements can be created.

If you want to save information that shouldn't be processed, you can use comments. These are created using angle brackets, exclamation marks, and hyphens.

What is it used for?

Let's take a look at the complete XML file. We see the drawing element with the attributes and child elements: house, garage and tree. The house has other child elements such as door, window and roof. And with the house it is also noticeable that there is an attribute position with the value on the left, attributes can also be found on other elements. Well, that's the complete syntax of XML.

Let's go over a slightly more realistic example. This time we don't have a drawing, but a text that should be shown in certain formats. Try to copy and format the text with the appropriate information.

Other languages, other elements

On the one hand, you can now read the XML format and you should learn about another use for XML. In both examples we made up elements. If you want the browser to display this text appropriately, you have to use the elements that are specified in the HTML language. The cutout would then look like this. If you open this file in the browser, the whole thing looks like this, i.e. exactly as it was originally intended.

So HTML has special elements that a browser can understand. You can then use it to create websites. For other purposes there are in turn their own languages ​​with their own elements. Do you remember our drawing?

With SVG and the appropriate elements, you can actually create such graphics. These languages ​​are now standard, but you can also create such languages ​​yourself.

However, you should always keep in mind that you have to write a suitable program that can then read and write this format. For your own formats there is an additional format with which you can define the valid elements, attributes and child elements, i.e. the structure of an XML. This is called XML Schema Definition or short XSD. In principle, this reads like an XML, but has a few special cases.

An XSD is always useful when you want to transfer the XML file between programs and computers.
It is also important that the XML does not contain any errors, otherwise your program cannot read them and the XML is therefore not considered to be well-formed.

Conclusion on XML

Finally, it should be mentioned that there are libraries for every common programming language that can be used to read and write XML. This makes working with XML data easier. A list of programming languages ​​and libraries can be found below the video.

Do you want to check whether you can now read XML?

Open the developer tools in your browser and take a look at the elements. Even if you don't know the elements yet, you can now see the structure of a website.

You now have everything you need to understand XML and all other XML-based languages. Now it is your turn to further develop and use this knowledge.

That was a little explanation about XML, you can find more information in the video description. If you liked this video, I'll be happy about a thumbs up and a subscription. For questions and suggestions, please use the comment function or simply write me an email.

Have fun learning to program and see you soon at lerneProgrammieren.de.