XML Basics


XML Elements vs. Attributes:

1
2
3
4
<person sex="female">
  <firstname>Anna</firstname>
  <lastname>Smith</lastname>
</person>

1
2
3
4
5
<person>
  <sex>female</sex>
  <firstname>Anna</firstname>
  <lastname>Smith</lastname>
</person>


In the first example sex is an attribute. In the last, sex is an element. Both examples provide the same information.

XML 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: <first_name>, <last_name>.
Avoid the following:
hyphen(-) , dot/period(.), colon(:)
Eg: first-name, first.name, first:name

Points to remember while parsing XML
1) XML is case sensitive
2) XML must have root tag ie. Only one open tag and close tag in entire XML.
3) Opening and closing tag must be same.
eg.
  1) <starT> </start>
   This tag may look same but alphabet T is capital in opening tag.
   So XML parser will not parse this xml

  2) <table1>  </table> --> this is also not allowed

No comments:

Post a Comment