XML Getting Started Tutorial: Understanding Learning XML Elements

Source: Internet
Author: User
Tags date contains empty mixed reserved
xml| Tutorials | Getting Started

XML elements are extensible, and there are certain relationships between them.

XML elements must adhere to some simple naming conventions.

XML elements are extensible

XML elements can be extended to carry more information.

Take a look at the XML tag example below:

<note><to>tove</to><from>jani</from><body>don ' t forget me this weekend!</ Body></note>

Let's imagine that we created an application that extracts the <to>, <from>, and <body> elements and produces the following output:

Message To:ToveFrom:JaniDon ' t forget me this weekend!

Imagine, then, that the XML document author added some additional information to the document:

<note><date>2002-08-01</date><to>Tove</to><from>Jani</from>< Heading>reminder

So will this application break or crash?

No. The application can still find the <to>, <from>, and <body> elements in the XML document and produce the same output:

XML documents are extensible.

There is a relationship between the XML elements

There is a parent-child relationship between the elements.

To understand the terms of XML, we need to understand how the relationship between XML is named and how the content of the element is described.

Imagine the description of a book:

My first Xmlxml introduction HTML concept XML syntax elements must have a close tag element must be properly nested

Imagine how an XML document describes the book:

<book><title> my first Xml</title><prod id= "33-657" media= "paper" ></prod><chapter >xml Introduction to the concept of <para>html </para><para>xml the concept of </para></chapter><chapter>xml syntax <para> elements must have closing tags </para><para> elements must be properly nested </para></chapter></book>

Book is the root element . Title, prod, and chapter are child elements of the book. Book is the parent element of title, PROD, and chapter. Title, prod and chapter are sibling elements or sisters , because they all have the same parents.

Element has content

Elements can have different content types.

An XML element starts with (and includes) the start tag of the element, to (and includes) the end tag of the element terminated.

An element can have element content, mixed content, simple content, or empty content. Elements can also have attributes.

In the example above, the book has element content because it contains other elements. Chapter has mixed content because it contains text and other elements. Para has simple content (or text content) because it contains only text. Prod has empty content because it does not carry information.

In the above example, only the PROD element has attributes. The value of the property named ID is "33-657". The value of the property named Medea is "paper".

Element naming

XML elements must adhere to the naming rules:

    • Names can contain letters, numbers, and other characters.
    • Names can't start with numbers or punctuation marks.
    • Names cannot start with the character "XML" (or XML, XML)
    • Name cannot contain spaces

When you "invent" the element name, please note and follow the following simple rules:

You can use any name without a reserved word, but ideally the name will be descriptive . It's also nice to use the underlined name.

Example: <first_name>,<last_name>

"-" and "." should be avoided in the name. For example, if you name an element "First-name", you may experience confusion when your software tries to extract the name from the beginning. Or if you name an element "First.name", your software might think that "name" is an attribute of the "a" object.

The element name can be any length you wish, but don't overdo it. The name should be shorter , such as: <book_title>, rather than:<the_title_of_the_book>.

XML documents often have a corresponding database in which the fields correspond to an element in an XML document. There is a practical experience in naming an element in an XML document using the name rules of the database .

non-English letters such as Éòá are also valid XML element names, but need to be aware of the problems that arise when software developers do not support letters.

you should not use ":" in an XML element namebecause it is a reserved word for use as a namespace (namespaces).



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.