<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Dana Arad on Medium]]></title>
        <description><![CDATA[Stories by Dana Arad on Medium]]></description>
        <link>https://medium.com/@danaarad4?source=rss-4cc3c82dc1f0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*tOYqj_i7RCPTEubz2MHRtw.jpeg</url>
            <title>Stories by Dana Arad on Medium</title>
            <link>https://medium.com/@danaarad4?source=rss-4cc3c82dc1f0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 20:36:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@danaarad4/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Understanding XML]]></title>
            <link>https://medium.com/@danaarad4/understanding-xml-4414ae1a5ec5?source=rss-4cc3c82dc1f0------2</link>
            <guid isPermaLink="false">https://medium.com/p/4414ae1a5ec5</guid>
            <category><![CDATA[xml]]></category>
            <category><![CDATA[dtd]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[data-management]]></category>
            <dc:creator><![CDATA[Dana Arad]]></dc:creator>
            <pubDate>Sat, 26 Feb 2022 19:19:34 GMT</pubDate>
            <atom:updated>2022-02-26T20:18:40.974Z</atom:updated>
            <content:encoded><![CDATA[<h4>An introduction to XML structure, hierarchy and validation</h4><p>In this post, I will walk you through the basics of XML, and the advantages of using XML to manage data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*_MCR4SoVovQMAVVE-MNrLA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@florianolv">Florian Olivo</a><strong> </strong>on <a href="https://unsplash.com/">Unsplash</a></figcaption></figure><p>XML, or <strong>Extensible Markup Language</strong>, is a language and a file format. It is both simple enough to be understood by humans, and structured enough to allow easy parsing and querying. XML allows us to model objects and their properties and represent hierarchy, and is one of the most popular formats for storing and transmitting data.</p><p>This post can be useful if you are new to data management, or if you are a student in the <em>web data management </em>course at Tel Aviv university I recite this semester, which this post — and hopefully next posts in this series — are based on.</p><h3>What is XML?</h3><p>Imagine you are a high-school manager, and you want to keep track of the different classes in your school. You want to define a data structure that can help you manage the classes, and the students who take them. One option is to manage your data in an <strong>XML</strong> <strong>document</strong>.</p><p>Our basic XML document consists of <strong>elements, </strong>each has an opening tag and a closing tag. Since we want to manage a list of classes, we start by defining an element with the same name:</p><pre>&lt;classes_list&gt;&lt;/classes_list&gt;</pre><p>Say that our classes are very similar to each other; each class has a class id, <br>a subject, and the name of the supervising teacher. We can use a class element to represent each class, and add the class’s metadata as <strong>attributes. </strong>Notice that XML attributes are quoted (single or double), and different attributes are listed one after the other without a separating comma.</p><pre>&lt;classes_list&gt;<br>     &lt;class id=&quot;1&quot; subject=&quot;Math&quot; teacher=&quot;Alice&quot;&gt;&lt;/class&gt;<br>     &lt;class id=&quot;2&quot; subject=&quot;English&quot; teacher=&quot;Bob&quot;&gt;&lt;/class&gt;<br>&lt;/classes_list&gt;</pre><h3>Elements vs. Attributes</h3><p>Another way to represent our class’s metadata is to add additional elements under the class element. Notice that this time we added text to our element. For example, the first class_id element now contains the text 1 (unquoted). This text can be accessed when parsing the document, and is used to store the element’s data.</p><pre>&lt;classes_list&gt;<br>     &lt;class&gt;<br>          &lt;class_id&gt;1&lt;/class_id&gt;<br>          &lt;subject&gt;Math&lt;/subject&gt;<br>          &lt;teacher&gt;Alice&lt;/teacher&gt;<br>     &lt;/class&gt;<br>     &lt;class&gt;<br>          &lt;class_id&gt;2&lt;/class_id&gt;<br>          &lt;subject&gt;English&lt;/subject&gt;<br>          &lt;teacher&gt;Bob&lt;/teacher&gt;<br>     &lt;/class&gt;<br>&lt;/classes_list&gt;</pre><p>Generally, representing information as elements is completely equivalent to representing it using attributes. My take is usually a mix of the two, where the key idea is that elements allow more flexibility for future changes:</p><ol><li>The representation of teachers as elements will allow us to add more information about them in the future (e.g. id, age and education).</li><li>Attributes hold a single value. Representing our teachers as elements will allow us to add as many teachers as we need under the same class element.</li><li>On the other hand, we may have pieces of information that their structure will not likely change in the future. This is usually the case for id, name, and age. These can be good candidates to become attributes.</li></ol><p>Using these guidelines, our data now looks like this:</p><pre>&lt;classes_list&gt;<br>     &lt;class id=&quot;1&quot;&gt;<br>          &lt;teacher&gt;Alice&lt;/teacher&gt;<br>          &lt;subject&gt;Math&lt;/subject&gt;<br>     &lt;/class&gt;<br>     &lt;class id=&quot;2&quot;&gt;<br>          &lt;teacher&gt;Bob&lt;/teacher&gt;<br>          &lt;subject&gt;English&lt;/subject&gt;<br>     &lt;/class&gt;<br>&lt;/classes_list&gt;</pre><h3>XML Tree</h3><p>The hierarchy of our XML document defines a tree. Each element has a parent element (except for the root) and can have child and sibling elements. This is particularly useful for querying XML documents (say using the querying language <strong>XPath, </strong>which we’ll cover in the next post), where we can utilize our knowledge of the document’s hierarchy to find the desired elements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*7elzm470-XTJHNarooCiVA.png" /><figcaption>Our XML tree</figcaption></figure><p>In our example, our root element is classes_list denoted in the tree above as CL. When querying XML trees, it is sometimes useful to add a special root node and have the actual root of our XML be a child of it. Such special root node is implicit, and is not defined in our XML document.</p><p>classes_list has two children, the two class elements in our document (C). Each class has two children of their own, the subject (S) and the teacher (T).</p><h3>Well-Formed and Validated XMLs</h3><p>We distinguish between two types of XML documents — well-formed and validated. A <strong>well-formed</strong> XML document is simply a document that has proper nesting. We can invent our own elements and any element can go anywhere we want.</p><p>A <strong>validated </strong>XML document follows a <strong>DTD </strong>(document type definition). A DTD declares the different elements and specifies conditions on nesting and the number of possible occurrences for each element .</p><p>The following DTD can help us validate the elements in our XML document and enforce structure if new information is added. For our purposes, we only want to declare the elements in our document, but it’s worth noting that attributes can be declared as well. Elements are declared with the following syntax:</p><pre>&lt;!ELEMENT classes_list (class*)&gt;<br>&lt;!ELEMENT class(teacher+, subject)&gt;<br>&lt;!ELEMENT teacher(#PCDATA)&gt;<br>&lt;!ELEMENT subject(#PCDATA)&gt;</pre><p>First, we defined the classes_list Element. According to our DTD, each classes_list element has zero or more class elements. Similarly to regular expressions, the notion of zero or more occurrences is marked with * after the element name.</p><p>Next, we declare the class element. According to our DTD, each class element can have two types of child elements —one or more teacher elements (defined by +) and exactly one subject .</p><p>Finally, we define the teacher and subject elements. These are the lowest elements in our hierarchy and only contains data, not other elements. This is declared using #PCDATA (Parsed Character Data).</p><h3>The Advantages</h3><h4>Flexibility</h4><p>As you may have noticed, the structure of our XML document is completely flexible. We can make up our own elements, determine the structure and hierarchy to fit our needs, and have different methods for representing our information. This is useful when designing our data format and allows for easy changes and updates.</p><h4>Simplicity</h4><p>XML is a very simple format. As a human it’s easy to read and understand, and the structure of the document makes it easy to parse it automatically.</p><h4>Generality</h4><p>XML is not platform dependent, so it is widely used as a format for communication between components. Many configuration files and APIs use XML as their format for data representation.</p><h3>What’s Next?</h3><p>Now that you are familiar with the basics of XML, we can learn how to query XML documents and how to enforce (special cases) of constraints on the structure of our documents. Let me know if you have any questions or comments!</p><p><em>Special thanks to Daniel Deutch, Slava Novgorodov, and Tomer Wolfson for creating and sharing the course materials over the years.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4414ae1a5ec5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>