Next freebie in 28 Hours*
The first step in learning about how information is structured in an XML document (the word “document” will be used to refer to information and its organization, typically stored in a disk file) will be to learn the syntactic components. The most basic component in XML is called an “element” or “node”: both are used inter-changeably in documentation.
An element consists of a “name” assigned to it, as well as the content which the name describes/defines. One can also use the word “tag” to describe a name, in conformance with HTML terminology. As it turns out, “tag” is popular universally, and in this document, we shall stick to this terminology. Each element has an opening tag, content (optional) and a closing tag. Sometimes, a single tag might be enough to describe an element, especially when no meaningful content can be stored between the opening and closing of a tag. Learning by example is the best way, so we will see a few below.
First let us look at what an element typically looks like:
The parts of this element are as follows:
• <name> is the opening tag, and “name” is the tag-name
• “Babe Ruth” is the content of the element, and here it is a character string
• </name> is the closing tag: note the forward-slash “/” at the beginning
Another example of an element is: <drinking minor=”yes” />
• Note here that there is only one tag, which both opens and closes the element; the tag name is “drinking”
• “minor” is called an “attribute” or “property” of the element. It has the value “yes” in this case.
XML, unlike HTML, is a case sensitive markup language. The content of an element can be a character string, an alphanumeric string, a number etc.; it can be any type of information that is normally used by people and applications. When it comes to tag names, the following exclusions apply:
• The word “XML” or “xml” cannot be used as a tag name… it is the ONLY reserved keyword in an XML document
• A tag name or attribute name cannot start with a numeric character; for example, “32age” is not a valid identifier (another name for tag or attribute name,) whereas “age32” is valid.
• You can't have a space character within an identifier name: for example, “player name” is not a valid identifier, while “player_name” is.
This ends the introduction to syntax and naming of tags and attribute names.
Have a question but don't want to ask it publicly? If you are a prime member just ask right here and we will get back to you within 48 hours. Not prime yet? no worries you can ask publicly below.