XML

Use of XML files

In E3.series for some applications XML files are used (Extended-Markup-Language files). These structured documents help, like scripts, to handle complex functionalities.

 

For example, XML files help to

 

A distinction is made between XML documents that

  • can be edited

  • can't be edited

  • are created automatically

  • have to be created by the user

 

Structure of XML documents

This is a well-formed XML document (An XML document is well-formed when a correct syntax and nesting is given):

 

<?xml version="1.0" encoding="utf-8" ?>
<!-- comment: information about the XML document -->
<root element>
    <content>element_without_content</content>
        <parent-element>
            <child-element>
            <child-element>
        </parent-element>
</root element>
<!-- comment: end of XML document -->

 

Each XML document consists of a Prolog, a Root Element (and its content) and Miscellaneous.

 

Prolog

<?xml version="1.0" encoding="utf-8" ?>

 

An XML document always starts with the XML declaration. The program that evaluates XML documents, the so called parser, recognizes by means of the XML declaration, that it is an XML documentation. The parser checks if the subsequent text complies with the XML specification. Thus, a well-formed XML document must contain the XML declaration in the first line.

 

Root Element, Parent-Elements and Child-Elements

<root element>
    <content>element_without_content</content>
        <parent-element>
            <child-element>
            </child-element>
        </parent-element>
</root element>

 

An XML document has exactly one root element, that contains all other elements with their content. Elements display the logical structure in XML, they divide the document into different logical components. Any number of elements can be created in XML.

 

An XML element consists of a start-tag and an end-tag. The start-tag starts with an open angle bracket (<), followed by its name, and ends with a closed angle bracket (>). The end-tag is followed by a slash after the open angle bracket (</), this distinguishes the end-tag from the start-tag.

 

An XML element contains either character data, like texts, or further XML elements. These further elements are so-called child-elements, and the element which contains these child-elements is a so-called parent-element.

 

Miscellaneous

<!-- comment: Information for the XML document -->

<!-- comment: End of the XML document -->

 

Comments can be used in the entire document, there are no restrictions. After the root element has been closed, only comments are allowed.

 

Attributes

A further option to organize data is given in the form of attributes. They consist of a name which can be used only once in an element, and a value that is enclosed in quotation marks. Thus, information about the element can be given by attributes. For attribute names, the same Spelling is valid as for elements.

 

Examples

  • <?xml version="1.0" ?>

     

    Here, version is the attribute.

  • <Attribute Name="SUBPROJ">

     

    Here, Name is the attribute.

 

Correct syntax and nesting in XML documents

The name of an element (attribute)

  • must start with a letter or an underline
    example:
    <Element> or <_Element>

  • may contain letters, numbers, points, hyphens or underlines
    example:
    <Element-12_3> or <_Element:08.15>

  • may contain emphases, umlauts or symbolism
    example:
    <À> or <Gläser> or <espa\na>

  • must not start with the letters xml or XML

  • must contain the appropriate data item reference instead of special characters (see table below)

 

Special characters

The XML markup language contains certain special characters that must not be used in the XML source code. Instead, the following syntax is valid:

 

Special character
Syntax in the XML source code

&

&amp;

<

&lt;

>

&gt;

"

&quot;

'

&apos;

 

Example

Write Variants &amp; Options instead of Variants & Options .

 

Case sensitivity

XML considers case sensitivity. The element's name must be completely identical with start and end-tag!

 

Example

<root element> </Rootelement>

<root element> </ROOT-ELEMENT>

<root element> </root-element>

Close opened elements

Each opened element must be closed. Open elements cause an interpretation being aborted:

 

Incorrect:

<p>A text is output.

 

Correct:

<p>A text is output.</p>

 

The following syntax is valid for elements without content

  • Long variant: <Element_without_content></Element_without_content>

  • Shortened variant: <Element_without_content/>

 

Correct nesting

Correct nesting of elements is important. Crossover nestings are not allowed. The following code is thus not well-formed:

<parent-element>
    <child-element>
</parent-element>
    </child-element>

 

Child-elements must be closed before closing the parent-element:

<parent-element>
    <child-element>
    </child-element>
</parent-element>

 

Comments

A comment is started with: <!--. And closed with -->.

  • There is no ! at the end.

  • Double dash within a comment is not allowed: --

 

Incorrect:

<!-- This is a comment -- But not well-formed -->

 

Incorrect:

<!-- This is a comment, but not well-formed --!>

 

Correct:

<!-- This is a comment -->