Log in / create account Page Discussion Edit History Go to the site toolbox

2SimpleXML

From BluWiki

Contents

[edit] Introduction

2SimpleXML is a variant or subset of XML. It is meant to be a simple alternative to the standard XML language. It can be used to create simplified XML documents or XML schemas. It is based partly on the ideas of Minimal XML. 2SimpleXML is is modeled around the concept of using schemas to provide information about the type of information contained in an XML element, rather that creating "special" elements for this purpose.


[edit] How Is It Different?

There are greater restrictions on the allowable content of a 2SimpleXML document than there are on a normal XML document. A valid 2SimpleXML document will not allow the following:

  • Attributes
  • Empty Elements
  • XML Comments
  • Processing Instructions
  • Mixed Content Elements (Elements that contain both text or character content and child elements.)
  • CDATA Sections or Entity References
  • Document Prolog or XML Declaration


[edit] Why Is 2SimpleXML Necessary?

  • 2SimpleXML will be easier to learn and understand.
  • 2SimpleXML will allow the construction of simpler XML parsers.
  • Many applications of XML require only a subset of the full XML specification. 2SimpleXML is designed for these types of applications.
  • You don't need all that other special stuff in XML. That's the beauty of structured markup. The tags identify the type of content, and the schema tells you all you need to know about the different types of content in a document.


[edit] 2SimpleXML Rules

[edit] Restrictions

Here is the list of items not allowed in a valid 2SimpleXMl Document:

  • Attributes
  • Empty Elements
  • XML Comments
  • Processing Instructions
  • Mixed Content Elements (Elements that contain both text or character content and child elements.)
  • CDATA Sections or Entity References
  • Document Prolog or XML Declaration

[edit] Root Element

All valid 2SimpleXML documents must contain a single element that contains all other elements. This element is known as the root element. No whitespace should proceed the root element.

[edit] Tags

In 2SimpleXML all elements must have a start and end tag. These tags are marked by the "<" and the ">" character. The ending tag of an element is indicated "</". Tags can contain any characters, but should not include whitespace. The "<" and ">" characters can be escaped in an element's content using the escape character, but can't be escaped as part of a tag name.

[edit] Element Content

In 2SimpleXML elements can contain child elements or text/character content, but not both. You may have a start tag and an end tag with no text/character content.

[edit] But how do I...

[edit] put a comment in my 2SimpleXML file?

You could use an element called comment. Here is an example:

<comment>This is an example of how you could place a comment in a 2SimpleXML file.</comment>

[edit] put a processing instruction in my 2SimpleXML file?

You could use an element called processingInstruction. Here is an example:

<processingInstruction>This is an example of how you could place a comment in a 2SimpleXML file.</processingInstruction>

[edit] avoid using attributes in my 2SimpleXML file?

Make your attributes a child element, and place the text/character content into its own child element. Here is an example:


Not Valid in 2SimpleXML

<car color="splotchy red and orange" type="junker" year="1979">This was my first car.</car>


Valid in 2SimpleXML

<car>
<color>splotchy red and orange</color>
<type>junker</type>
<year>1979</year>
<description>This was my first car.</description>
</car>

In this example we transformed each attribute of the car element into a child element, and placed the content into its own description child element. (This is necessary because an element in 2SimpleXML can't contain text/character content child elements.)

Site Toolbox:

GNU Free Documentation License 1.2
This page was last modified on 10 February 2006, at 19:26. - This page has been accessed 1,682 times.
Disclaimers - About BluWiki