Technology Programming

How XML Works

    Elements

    • XML data is organized into elements, each delineated by a set of tags as follows:

      <cat>Pebbles</cat>

      Each element in XML must have an opening and closing tag as in this example. An XML document can contain any tags the developer chooses, so XML data can fulfill the needs of virtually any application. Many programs use XML instead of a database, with XML elements reflecting the tables and columns you might expect in a relational database system.

    Attributes

    • XML elements can contain attributes as follows:

      <animal type="cat">Pebbles</animal>

      Developers choose whether to implement a particular item of data as an element in its own right, or as an attribute of another element. Generally, attributes are used to provide additional information that is not seen as a central characteristic of the data contained in an element. Attributes are an example of the flexibility of XML, as developers can choose whichever arrangement best suits the purpose of the project they are working on.

    Parents and Children

    • XML data adopts a tree structure. This means that elements can contain other elements. Where an element contains further elements, these contained elements are referred to as "child" elements of the "parent"-containing element. The following example demonstrates parent and child elements in a tree structure:

      <company name="Cool Products Inc">

      <employee>Martha Smith</employee>

      <employee>James Simpson</employee>

      </company>

      The "employee" elements are children of the parent "company" element. The document could optionally contain further "company" elements structured in the same way and listed before or after the existing one.

    Validation

    • XML documents are only effective if they are properly structured. This means that no syntax errors can appear, and all elements must be closed correctly. Errors in an XML data store can have a direct impact on any applications making use of it. To avoid including errors in XML, developers can use programs that are specifically designed to edit and display XML data, as these typically highlight errors. Developers can also use Web validation tools to check whether their XML is well-formed.

    XML Schema

    • Because XML is flexible, an XML document can contain any elements at all. XML Schema Definitions define the structures that are permitted within a certain set of XML documents. This allows developers to create their own set of syntax rules for the XML data that is used within certain applications. Having a specified set of rules for XML data makes an application more robust and reliable as well as easier to work with. Developers can validate XML against particular XML Schemas, to make sure the data is correctly formed.



Leave a reply