Introduction to XML, exercices

v1.0.0
2022-10-10

Introduction to XML

Basics

Transform this XML tree into an XML document

Transform this XML document into a tree

<?xml version="1.0" encoding="UTF-8"?>
<Race date="2020-12-15" name="Holiday Meet">
    <Course>
        <CourseName>The track</CourseName>
        <Address>Track road 123</Address>
    </Course>
    <Horses>
        <Horse name="Bonfire">
            <Value>5000</Value>
            <Birthdate>1998-05-01</Birthdate>
            <Gender>M</Gender>
        </Horse>
        <Horse name="Dobby">
            <Value>1000</Value>
            <Birthdate>2001-04-05</Birthdate>
            <Gender>F</Gender>
        </Horse>
        <Horse name="Pegasus">
            <Value>10000</Value>
            <Birthdate>2000-01-01</Birthdate>
            <Gender>F</Gender>
        </Horse>
    </Horses>
</Race>

Make your own

From this description, create your own XML document format, start with a tree and then write the XML document.

Beef Parmesan with Garlic Angel Hair Pasta

Ingredients

Directions

Preheat oven to 175 degrees C.

Cut cube steak into serving size pieces. Coat meat with the bread crumbs and parmesan cheese. Heat olive oil in a large frying pan, and saute 1 teaspoon of the garlic for 3 minutes. Quick fry (brown quickly on both sides) meat. Place meat in a casserole baking dish, slightly overlapping edges. Place onion rings and peppers on top of meat, and pour marinara sauce over all.

Bake at 175 degrees C for 30 to 45 minutes, depending on the thickness of the meat. Sprinkle mozzarella over meat and leave in the oven till bubbly.

Boil pasta al dente. Drain, and toss in butter and 1 teaspoon garlic. For a stronger garlic taste, season with garlic powder. Top with grated parmesan and parsley for color. Serve meat and sauce atop a mound of pasta!

HINT: make the meat ahead of time, and refrigerate over night, the acid in the tomato sauce will tenderize the meat even more. If you do this, save the mozzarella till the last minute.

DTD definitions

Install the XML extension on vscode:

Define a complete DTD for the previous examples (the cookbook and the race track)

Test the validy of your XML documents with your DTD definition.

XML Schema Definition (XSD)

Write the XML Schema Definition (XSD) and the previous recipe example and validate the document.

Python XML API

Extract the information from the XML file using the python xml.etree.ElementTree library and make an interactive command line python app with a menu to list and print the different recipes of a cookbook in the terminal.