Monday, January 11, 2010

XML Elements,Attributes

Categories:

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.

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: , .
Names should be short and simple, like this: not like this: .
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 Attributes

XML elements can have attributes in the start tag, just like HTML.
Attributes provide additional information about elements.

XML Attributes Must be Quoted


or like this:

Some of the problems with using attributes are:

  • attributes cannot contain multiple values (elements can)
  • attributes cannot contain tree structures (elements can)
  • attributes are not easily expandable (for future changes)                                                                                               The ID above is just an identifier, to identify the different notes. It is not a part of the note itself.What I'm trying to say here is that metadata (data about data) should be stored as attributes, and that data itself should be stored as elements.

Spread The Love, Share Our Article

Related Posts

No Response to "XML Elements,Attributes"

Post a Comment