xml Building blocks Elements


Example

Elements come with angle brackets are the most prominent building block of XML.

Elements can either be empty, in which case they are made of an empty tag (notice the ending slash):

<an-empty-element/>

Or they can have content, in which case they have an opening tag (no slash) and a closing tag (beginning slash):

<a-non-empty-element>Content</a-non-empty-element>

Elements can nest (but only between opening and closing tags):

<parent-element>
  <child-element/>
  <another-child-element>
    Some more content.
  </another-child-element>
</parent-element>

Element names are called QNames (qualified names). All above elements are in no namespace, but element names can also be defined in namespaces using prefixes like so:

<my-namespace:parent-element xmlns:my-namespace="http://www.example.com/">
  <my-namespace:child-element/>
  <my-namespace:another-child-element>
    Some more content.
  </my-namespace:another-child-element>
</my-namespace:parent-element>

Namespaces and element names are described in greater details in this section of the documentation.