XML basics



To start my blogging with what ever little I know here is some basic stuff for beginners of XML. I have worked almost more than 4 years with XML and related technologies. It was really a cool stuff I found it to be handy, flexible and standard stuff.



To start with XML I want to tell you something, XML stands for eXtensible Markup Language. As the name indicates it is an open standard that can grow and is defined by markups. Here it comes some common points to remember when you do your XML



  1. Defining an XML File:XML is a very easy language to use and maintain. There are just a few steps to follow to successfully make an XML file. The first thing to do is do define the document as an XML file. An XML file doesn't have to end in a .xml entension, all it needs is the first line to be


    <?xml version="1.0" encoding="UTF-8"?>


  2. Closing and Opening Tags:It is safe to say that that the line above is the only thing in XML that doesn't need a closing tag. Unlike HTML, every tag you make in the XML file needs an open and closing tag. You can make up any type of a name for the type, as long as you open and close it. This includes any tag you might want to make for images, links, etc. For instance, in the following code, see how the spoono tag is opened and closed?:

    <mytag>Hi</mytag>


  3. Tags are Case Sensitive:Unlike HTML, XML tags are case-sensitive and defining one doesn't mean the same as the other. For instance, this would give you an error:


    <mytag>Hi</MYTAG>


  4. Nesting:Every tag must be inside the root element tag which must encompass all the other sub-elements. This pretty much means that in our script, all the coding we do must be inside the <mytag></mytag> and you can't have multiple instance of the mytag tag. Everything must be nested inside this immense mytag tag. Also, tags must be closed in the reciprocating order as they are open. For example:

    <mytag>
    <title><b>mytag Rocks</b></title>
    <news>I'm writing a tutorial</news>
    </mytag>


  5. Attributes:In any given tag, you're allowed to have as many attributes as you want. To give an example of an attribute, the "href" in the "a" tag of an HTML link is an attribute. So is the "src" in an "image" tag, etc. All the attribute values inside the tag must be in quotes. For example:


    <mytag>
    <title type="post"><b>mytag Rocks</b></title>
    <news author="Reflex Demon" date="23/07/08">I'm writing a tutorial!</news>
    </mytag>
Conclusion:
As you can see, there aren't too many rules to follow for writing XML code. It is really the parser for XML which has to do the grunt work by reading the XML file and making it look useable to a viewer. If you have any questions, feel free to post on the discussion board by clicking the link below and someone will be sure to help.

Comments

  1. Good my little brother. Keep posting and happy blogging.

    ReplyDelete
  2. I am planning to bring SAX and DOM next. If you are interested than don't forget to check back.

    ReplyDelete
  3. Hey.. SAX and DOM is old stuff... Can you put something on XSL, XSL:FO, XSLT ??? :)

    ReplyDelete
  4. Sachin,

    I know these are old, let me start with that. Thanks for giving me the next set of topics. I will add these to the queue.

    ReplyDelete

Post a Comment

Popular posts from this blog

Java SSL/TLS Testing Tool: Cipher Suite

PWA: Building and publishing a PWA in 15ish minutes using Angular 5 and Service Worker

Yarn and Angular-CLI