A.M.Senthilkumar: Changepond Technologies LTD
A.M.Senthilkumar: Changepond Technologies LTD
A.M.Senthilkumar: Changepond Technologies LTD
Senthilkumar
(eMeter-PIPe)
What is XML?
data. XML stands for EXtensible Markup Language XML is a markup language much like HTML XML was designed to carry data, not to display data XML tags are not predefined. You must define your own tags XML is designed to be self-descriptive XML is a W3C Recommendation XML uses a DTD (Document Type Definition) to formally describe the
An
XML Syntax All XML elements must have a example XML document closing tag <?xml version="1.0"?> XML tags are case sensitive <note> All XML elements must be <to>Tove</to> properly nested <from>Jani</from> All XML documents must have <heading>Reminder</heading> a root tag <body>Don't forget me this weekend!</body> Attribute values must always be quoted </note>
XML Validation
"Well Formed" XML documents A "Well Formed" XML document is a document that conforms to the XML syntax rules The following is a "Well Formed" XML document: <?xml version="1.0"?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
"Valid" XML documents A "Valid" XML document is a "Well Formed" XML document which conforms to the rules of a Document Type Definition (DTD). The following is the same document as above but with an added reference to a DTD: <?xml version="1.0"?> <!DOCTYPE note SYSTEM "InternalNote.dtd"> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
Intoduction to DTD
A Document Type Definition (DTD) defines the legal building blocks of an XML document. It defines the document structure with a list of legal elements and attributes. A DTD can be declared inline inside an XML document, or as an external reference.
If the DTD is declared inside the XML file, it should be wrapped in a DOCTYPE definition with the following syntax: <!DOCTYPE root-element [element-declarations]> Example XML document with an internal DTD: <?xml version="1.0"?> <!DOCTYPE note [ <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> ]> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend</body> </note>
External DTD Declaration If the DTD is declared in an external file, it should be wrapped in a DOCTYPE definition with the following syntax: <!DOCTYPE root-element SYSTEM "filename"> This is the same XML document as above, but with an external DTD <?xml version="1.0"?> <!DOCTYPE note SYSTEM "note.dtd"> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> And this is the file "note.dtd" which contains the DTD: <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)>
Empty Elements
Empty elements are declared with the category keyword EMPTY: <!ELEMENT element-name EMPTY> Example: <!ELEMENT br EMPTY> XML example: <br />
Elements declared with the category keyword ANY, can contain any combination of parsable data: <!ELEMENT element-name ANY> Example: <!ELEMENT note ANY>
Elements with one or more children are declared with the name of the children elements inside parentheses: <!ELEMENT element-name (child1)> or <!ELEMENT element-name (child1,child2,...)> Example: <!ELEMENT note (to,from,heading,body)>
The full declaration of the "note" element is: <?xml version="1.0"?> <!ELEMENT note (to,from,heading,body)> <!DOCTYPE note SYSTEM "note.dtd"> <!ELEMENT to (#PCDATA)> <note> <!ELEMENT from (#PCDATA)> <to>Tove</to> <!ELEMENT heading (#PCDATA)> <from>Jani</from> <!ELEMENT body (#PCDATA)>
<heading>Reminder</heading> <body>Don't forget me this weekend!</body> <!ELEMENT element-name (child-name)> </note> Example:
Examples (DOM Parser) Creating Blank DOM Document Creating DOM Child Elements Getting The XML Root Element To Count XML Element XML Well-Formed-ness Searching an Element in the given XML Document Create - XML File (Document) Regenerating XML file XML Error checker and locater (DOM) Getting all XML Elements Adding DOCTYPE to a XML File Getting Dom Tree Elements and their Corresponding XML Fragments Cloning a XML Element Remove Element from XML Document Getting Data from XML File (Document) Storing Data (Retrieved from a XML Document) to a File XML Validate DTD
References
http://www.w3schools.com
http://www.roseindia.net http://www.xmlfiles.com/xml/xml_intro.asp
http://www.techinterviews.com/?p=203
Thank You...