XML Elements

What is an XML Element? An XML element is everything from (including) the element's start tag to (including) the element's end tag....

What is an XML Element?

An XML element is everything from (including) the element's start tag to (including) the element's end tag.
An element can contain other elements, simple text or a mixture of both. Elements can also have attributes.

<book category="CHILDREN">
  <title>Harry Potter</title> 
  <author>J K. Rowling</author> 
<book category="WEB">
  <title>Learning XML</title> 
  <author>Erik T. Ray</author> 

In the example above, <bookstore> and <book> have element contents, because they contain other elements. <author> has text content because it contains text.
In the example above only <book> has an attribute (category="CHILDREN").

XML Naming Rules

XML elements must follow these naming rules:
  • Names can contain letters, numbers, and other characters
  • Names cannot start with a number or punctuation character
  • Names cannot start with the letters xml (or XML, or Xml, etc)
  • Names cannot contain spaces
Any name can be used, no words are reserved.

Best Naming Practices

Make names descriptive. Names with an underscore separator are nice: <first_name>, <last_name>.
Names should be short and simple, like this: <book_title> not like this: <the_title_of_the_book>.
Avoid "-" characters. If you name something "first-name," some software may think you want to subtract name from first.
Avoid "." characters. If you name something "first.name," some software may think that "name" is a property of the object "first."
Avoid ":" characters. Colons are reserved to be used for something called namespaces (more later).
XML documents often have a corresponding database. A good practice is to use the naming rules of your database for the elements in the XML documents.
Non-English letters like éòá are perfectly legal in XML, but watch out for problems if your software vendor doesn't support them.

XML Elements are Extensible

XML elements can be extended to carry more information.
Look at the following XML example:

<body>Don't forget me this weekend!</body>

 Let's imagine that we created an application that extracted the <to>, <from>, and <body> elements from the XML document to produce this output:

From: Jani
Don't forget me this weekend!

Imagine that the author of the XML document added some extra information to it:

<body>Don't forget me this weekend!</body>

Should the application break or crash?
No. The application should still be able to find the <to>, <from>, and <body> elements in the XML document and produce the same output.
One of the beauties of XML, is that it can often be extended without breaking applications.

Best Online Tutorials | Source codes | Programming Languages: XML Elements
XML Elements
Best Online Tutorials | Source codes | Programming Languages
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content