<name>
<name age="29" sex="M" looks="good">
<name xmlns=http://www.leistware.com/dtd/MyDtd.dtd
>
</name>
<name age="29" sex="M" looks="good">kenny</name>
<name first="Kenny" age="29" sex="M" looks="good" />
<person age="29" sex="M" looks="good">
<firstname>Kenny</firstname>
<lastname>L</lastname>
</person>
<!CDATA[note:CDATA sections are transfered as-is
]]>
- marks the boundries of an element. The tag is:
The Tag
- always delimited with
<
and >
e.g. < tagname >
-
must be a qualified xml tag name - begin with a number or
xml
in any case
can not
- is case sensitive -
<name></name>
but not <name></Name>
- can not contain spaces within the name - spaces indicate attributes.
There are two types of tags. The open tag and the close tag.
The Open Tag - can contain attributes in name/value pairs e.g. name=kenny
. Attribute values must be contained in quotes if there is spaces in the value. However, it is a good idea to contain all values in quotes. e.g. name=Kenny
and name="Kenny"
are both valid. However name=Kenny L
would throw a parse error and need to be contained in quotes i.e. name=Kenny L
The open tag can also contain namespace references. Namesspace references indicated a seperate document that defines the specifics about the tag.
The Closing Tag - encased in < >
but the name begins with a slash /
. The name MUST be the same as the open tag (case sensitive). e.g.
is made up of a set of tags that may or may not encase data. There are two kinds of elements. The element and the empty element. An empty element has no data. In the interest of saving bytes, the empty element may omit the closing tag but not the slash.
The Element
The element:
The empty element: make the data an attribute
Elements can be nested but not overlapped. Empty elements can not have children (other elements nested inside). In this example person
could be an empty element but it would have to dump it's kids.
- To reference key characters
like (<
) an entity reference must be used so that the parser doesn't get confused. An entity reference begins with an ampersand &
and ends with a semi-colon ;
. For example: <
would make the <
symbol (lt = LessThan), and >
would make the >
symbol.
Entity Reference
Sometimes entity references can become messy... an ocean of &'s. For this reason the CDATA section transferes all data as-is
CDATA