I’m a bit confused with xml, and my understanding of it is very primitive at this point, so I am going to track back to the very beginning in efforts to make sense of what we have talked about thus far…
Let’s start with the structure of xml. Based on the O’Reilly article, I understand that there are two primary components… the document prolog and the document element. I gather that the document element is more important than the document prolog based on the fact that all of the fields in the document prolog are optional. Therefore, focusing on the document element, the article gives the following example:
<telegram pri=“important”>
<to>Sarah Bellum</to>
<from>Colonel Timeslip</from>
<subject>Robot-sitting instructions</subject>
<graphic fileref=”figs/me.jpg”/>
<message>Thanks for watching my robot pal<name>Zonkey</name>
…
</telegram>
I’m assuming that each tag indicates the beginning of a new section. So the following document contains the sections: to, from, subject, graphic, and message. From a past Information Studies class that I took, I remember learning that xml doesn’t really define how a document is displayed. Therefore, are the tags just this intuitive sense of organization to give the parser a sense that this document has 5 sections, and therefore it doesn’t really matter what you name them? If this is the case, is your only incentive for choosing logical tag names to provide clarity for anyone reading the xml script? Or, do the name of tags actually matter? I know that you can have a blank tag, but does the name actually appear someplace within the document text? For example, would the first line of the above document display “to Sarah Bellum” or just “Sarah Bellum”? I am also confused about attributes. From the article, I gather that you can have multiple elements with the same name, but every attribute of an element must have a unique name. Can attributes of different elements have the same name? For example, if you had the elements “cake” and “ice-cream,” could you use the same attribute name “chocolate” for each? In the above example, I know that “figs/me.ipg” is an attribute of graphic fileref, but I am confused as to what purpose this attribute is serving. The article says that you use attributes to specify categories of elements so that you do not have to create a new element for every situation. Is it a bad thing if you create a document with 500 different elements? In the above example, this does not seem to be the reason that they defines “figs/me.jpg” as an attribute due to the fact that there is only one graphic fileref element listed.
Also, I am confused about the concept of the root element. Is it correct to think of it in the same sense as the title of a document? Just like a document can only have one title, the elements of an xml script can only have one root element?
Comments