1 / 27

XML

XML. UNIT 2. Overview. XML stands for EXtensible Markup Language. XML was designed to describe data. XML is a software- and hardware-independent tool for carrying information. XML is easy to learn. Sample XML. <?xml version="1.0" encoding="UTF-8 " ?> <note> <to> Tove </to>

faraji
Download Presentation

XML

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. XML UNIT 2

  2. Overview • XML stands for EXtensible Markup Language. • XML was designed to describe data. • XML is a software- and hardware-independent tool for carrying information. • XML is easy to learn.

  3. Sample XML <?xml version="1.0" encoding="UTF-8"?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>

  4. HTML vs XML • XML was designed to describe data. • HTML was designed to display data. • XML is not a replacement for HTML. • XML and HTML were designed with different goals: • XML was designed to describe data, with focus on what data is • HTML was designed to display data, with focus on how data looks • HTML is about displaying information, while XML is about carrying information.

  5. What is XML? • XML stands for EXtensible Markup Language • XML is a markup language much like HTML • XML was designed to describe 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

  6. Facts on XML • XML Does Not DO Anything • With XML You Invent Your Own Tags • XML Separates Data from HTML • XML Simplifies Data Sharing • XML data is stored in plain text format. • XML Simplifies Data Transport • XML Simplifies Platform Changes • XML Makes Your Data More Available

  7. XML Tree

  8. XML Syntax Rules • All XML Elements Must Have a Closing Tag • XML Tags are Case Sensitive • XML Elements Must be Properly Nested • XML Documents Must Have a Root Element • XML Attribute Values Must be Quoted • Well Formed XML • XML documents that conform to the syntax rules above are said to be "Well Formed" XML documents.

  9. XML Element • 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 • text • attributes • or a mix of all of the above...

  10. XML Attributes • Attributes provide additional information about an element. • XML Attributes Must be Quoted • <person sex="female"> • <person sex='female'> • XML Elements vs. Attributes

  11. XML Encoding • XML documents can contain international characters, like Norwegian æøå, or French êèé. • To avoid errors, you should specify the encoding used, or save your XML files as UTF-8. • UTF-8 - The Web Standard • The first line in an XML document is called the prolog: • <?xml version="1.0"?>

  12. Displaying XML with CSS • CSS can be used to format an XML document. • Formatting XML with CSS is not the most common method. • W3C recommends using XSLT instead.

  13. XML Validation

  14. Valid XML • An XML document with correct syntax is called "Well Formed". • A "Valid" XML document must also conform to a specified document type. • XML DTD and XML Schema are used validate XML documents.

  15. XML DTD • DTD is to define the structure of an XML document. • It defines the structure with a list of legal elements.

  16. Sample DTD <!DOCTYPE note[<!ELEMENT note (to,from,heading,body)><!ELEMENT to (#PCDATA)><!ELEMENT from (#PCDATA)><!ELEMENT heading (#PCDATA)><!ELEMENT body (#PCDATA)>]>

  17. XML Schema • XML Schema is an XML-based alternative to DTD. • <xs:element name="note"><xs:complexType>  <xs:sequence>    <xs:element name="to" type="xs:string"/>    <xs:element name="from" type="xs:string"/>    <xs:element name="heading" type="xs:string"/>    <xs:element name="body" type="xs:string"/>  </xs:sequence></xs:complexType></xs:element>

  18. XML Parsing

  19. XML Parser • All modern browsers have a built-in XML parser. • It is a software library (or a package) that provides methods (or interfaces) for client applications to work with XML documents • It checks if XML is well formed • It may validate the document.

  20. XML Parser

  21. DOM Parser • A DOM parser creates an internal structure in memory which is a DOM document object • Client applications get the information of the original XML document by invoking methods on this Document object or on other objects it contains • DOM parser is tree-based (or DOM obj-based) • Client application seems to be pulling the data actively, from the data flow point of view

  22. SAX Parser • It does not first create any internal structure • Client does not specify what methods to call • Client just overrides the methods of the API and place his own code inside there • When the parser encounters start-tag, end-tag, etc., it thinks of them as events

  23. SAX & DOM

  24. XML DOM • A DOM (Document Object Model) defines a standard way for accessing and manipulating documents. • The XML DOM views an XML document as a tree-structure.

  25. What is the XML DOM? • The XML DOM is: • A standard object model for XML • A standard programming interface for XML • Platform- and language-independent • A W3C standard • The XML DOM defines the objects and properties of all XML elements, and the methods (interface) to access them. • In other words: The XML DOM is a standard for how to get, change, add, or delete XML elements.

  26. XML DOM Nodes • In the DOM, everything in an XML document is a node. • The entire document is a document node • Every XML element is an element node • The text in the XML elements are text nodes • Every attribute is an attribute node • Comments are comment nodes

  27. XML Parser • The XML DOM Parser contains methods to traverse XML trees, access, insert, and delete nodes. • The XML document must be loaded into an XML DOM object first. • An XML parser reads XML, and converts it into an XML DOM object that can be accessed with program. • Most browsers have a built-in XML parser.

More Related