I'll say right at the start that this question is a bit pedantic, but I want to make sure I'm using the technical language accurately when referring to parts of an XML document.
Given the following,
<p></p>
What should I call the <p>? Is it an "element" or is it a "tag"?
What should I call the p? Is it a "name" or is it a "type"?
According to the W3C Recommendation, (Extensible Markup Language (XML) 1.0 (Fifth Edition), ยง 3.1):
The Name in the start- and end-tags gives the element's type.
It sounds like element and tag and name and type are used interchangeably. When should I use each?
<p> and </p> are each "tags" and the two together form an "element". "p" is the element's "type" and the tags' "name". In both cases, it's a distinction without much of a difference the vast majority of the time.
Don't stress yourself out.
If you want to get really pedantic:
An element is composed of tags (e.g. a start-tag and end-tag as in <termdef></termdef> or an empty-element tag as in <br/>), but it is important to note that the tags are individual parts of the whole element, so in very technical XML writing it is appropriate to distinguish between an element and its tags.
An element MUST have a type, while a tag MUST have a name, however the name(s) of the tag(s) MUST match the type of the element.
Therefore:
If you are specifically discussing a tag then it is most appropriate to use the term "name" (e.g. termdef is the name of the close-tag </termdef>)
If you are discussing a whole element, then it is most appropriate to use the term "type" (e.g. termdef is the type of the element <termdef></termdef>)
However... in my experience, it may cause more confusion than clarity to insist on the "correct" terminology as the distinction is really only relevant when working on low-level XML parsers.
For most folks, even an otherwise technical crowd, it's probably going to be most helpful to pick one or the other term (whichever will be most clearly understood by the target audience) and just stick with it. (Maybe "tags" and "names" for business folks and "elements" and "types" for uppity technical types ๐)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With