Naming and Relations
How do you name XML tags? How will you easily grasp the concept of relationships? Know how the basics of naming and renaming relations in the XML programming language.
Naming
Aside from the case sensitivity, nesting, and closing rules associated with XML tags, you also have to be familiar with the kinds of names that you can give to your XML tags. Although there are no reserved names in the XML language, you still have to make your XML tags as descriptive as possible. For instance, if you want to make a tag for dates then use date as your tag and not simply the letter d. Some other pointers that you should keep in mind are the following:
- You can use all the alphanumeric characters on your keyboard when making your XML tags. You can use the letters A to Z and the numbers 0 to 9. Keep in mind the case sensitivity rule in the previous chapter. A is different from a.
- The only restricted tag is the character string XML itself. You can not use XML, Xml, xml, etcetera... as your tags.
- You can not begin your XML tag with a number or a punctuation mark.
- You can not use spaces in your XML tags. Use the "_" character instead.
- Avoid using the "-" and "." characters in your XML tags. Some software out there may misinterpret these symbols as a subtraction operation or a property command, respectively.
Relationships
Since you have familiarized yourself with nesting in the previous chapter, you will now be able to grasp the concept of relationships easily. When it comes to relationships, you simply have to identify the root, the parent, and the child.
Take a look at the code below:
<postit>
<to> Giselle </to>
<from> Alessandra </from>
<message> hey there, ill see you at the beach </message>
</postit>
Notes:
- postit is the root element.
- to, from, and message are child elements of postit.
- postit is the parent element of to, from, and message.
- to, from, and message are sibling elements of each other.