Elements are also the key building blocks of XML and is also one of several benefits XML provides over other languages. In XML you may create your very own element tags to match your own requirements.
With other languages, like HTML or PHP, you can just use predetermined labels which are particular to that language. In HTML by way of example you are only have body elements within the <body> tag and header elements inside the <head> tag. This is certainly tough and even time intensive and means you need to comprehend the language and syntax as well as where it goes to create web pages.
This is where XML is special, you can make your own personal elements and title these to suit your own purposes, allowing it to be entirely possible for newbie’s to grasp and apply XML.
So what are XML elements? Pretty much elements are names that are assigned to areas of data or information. As an example, let’s say you want to develop a catalogue of all your household items for insurance applications.
You could potentially try to portion items by room after which further sub divide by value etc. In XML the parser will look at the construction compared to names of the elements, in HTML it will be the other way round, the labels will be more significant for the parsing to be successful.
While XML is a lot more focused on structure, versus naming conventions, you'll still have to comply with some fundamental guidelines when creating elements. The first element is considered as the root; the root element consists of all the other elements inside it, similar to a folder contains sub folders and files.
After the root, the following element is called the parent and inside the parent are child elements, not all parent elements have to have child element, it will be at your discretion and is determined by how and just what you want to design your XML for.
The key point to creating a XML file that can be easily parsed is with the organisation, you need to make your elements to make sure they appear sensible from a structural perspective.
For example if you're a constructing a stock list of your products, it might make more sense to have products as your root element and then the categories as the parent and then individual category products as the child elements.
Having a well laid and common sense structure is going to pay off in the long term when you need to handle updates or parsing as all the elements will naturally fit into place.
Along with element structure and naming, its also wise to keep the following easy tips in mind too.
Each and every element tag requires a opening and closing syntax ie <xml> and </xml>, if you forget you will receive an error message whenever you try and validate or parse your xml file.
Be sure you organize your element names intelligently and rationally. Name your tags in a means by which is smart to you.
Root element
Parent element
Child element
Two parent elements for the product stock list could have child tags named ‹product›. In fact, parent names may also be the same.
Product - root element
Item - parent element
Item - parent element
So that’s a rapid and straightforward look at xml and how to write an xml file, to study more advanced material, you can search Google or view this xml tutorial.
No comments:
Post a Comment