Your SlideShare is downloading. ×

Session 5

753
views

Published on

XML by Example Session 5

XML by Example Session 5

Published in: Technology, Education

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
753
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
48
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Session 5 DOM and SAX, XML DOM and SAX Objects Create by ChungLD faculty XML by Example / Bachkhoa – Aptech Computer Education /31
  • 2. Objectives
    • Representing data
    • Parsers
    • DOM
    • Working with DOM
    • SAX
    • Microsoft XML DOM objects
    Create by ChungLD faculty /31
  • 3. Representing Data
    • Model: is a way of representing data or information. The data within XML documents can be represented using various models.
    • The various documents models available
    Create by ChungLD faculty /31 Linear model Tree model Object model
  • 4. Linear Model
    • The linear model can be applied to a static document object, such as book.
    • To go to a particular topic in a book, the
    • book name, page number, and the line
    • number on that page is the only
    • information required.
    Create by ChungLD faculty /31
  • 5. Tree model
    • XML documents can have a hierarchical structure which can be interpreted as a tree structure, known as XML tree. A tree consists of nodes and at every node in the tree there are character strings.
    Create by ChungLD faculty /31 Inventory Snacks Drink Fitzy Tipsy Popcorn Wafers Quantity Price Quantity Price Quantity Price Quantity Price
  • 6. Object Model
    • The XML object model is a collection of objects that is used to access and manipulate the data stored in an XML document. The XML document is modeled like a tree, in which each element in the tree is considered a node. Objects with various properties and methods are used to traverse the tree and its nodes. Each node contains the data in the document.
    Create by ChungLD faculty /31
  • 7. Parsers
    • An XML parser is a software package, a libraray or a module that reads XML documents first. The information present in the XML file is then made available by the parser to applications and other programming languages
    Create by ChungLD faculty /31
  • 8. Parsing Techniques
    • It is important to parse XML data efficiently, especially in applications that handle large volumes of data. Improper parsing will result in excessive memory usage and processing time that will hamper scalability.
    Create by ChungLD faculty /31 Parsing Event-driven Parsing Object-based Parsing
  • 9. Types of parsers
    • The different types of parsers are:
    Create by ChungLD faculty /31
  • 10. Simple API for XML (SAX):
      • SAX gives an event based approach to XML parsing. In an event based parsing when the parser encounters an element, the parser returns the elements, its attribute and content. Event based parsing provides a data – centric view of XML. Events include XML tag, detecting errors and so on.
      • Advantages:
        • Low memory consumption as the entire XML document is not loaded in the memory
      • Disadvantages:
        • No built-in document navigation support
        • No support for random access of XML document
        • No namespace and modifying XML document support in place
    Create by ChungLD faculty /31
  • 11. Document Object Model(DOM)
      • DOM is a mature standard from W3C. DOM parser builds a hierarchical model of the parsed document. Each of the important locations in the document, various element and attribute containers and characteristics of the model is represented as nodes.
      • Advantages:
        • Easy to use. Easy navigation by using the APIs. Random access to XML document as the tree is loaded in the memory
      • Disadvantages:
        • Parsing of the XML document is done once. High memory consumption and expensive as the entire tree structure is loaded in the memory
    Create by ChungLD faculty /31
  • 12. Streaming API for XML (StAX)
      • The StAX is a new parsing model introduced recently. Like SAX it is an event-driven model. StAX uses pull model for event processing. In other words, StAX parser returns events that are requested by an application and the events can also be provided as objects.
      • Advantages:
        • Ease in performance as it supports two parsing models. Parsing controlled by application
      • Disadvantages:
        • No built-in document navigation support
        • No support for random access XML document
        • No support for modifying XML document
    Create by ChungLD faculty /31
  • 13. Introduction DOM
    • A standard object model for XML
    • A standard programming interface for XML
    • Platform- and language-independent
    • A W3C standard
    Create by ChungLD faculty /31
  • 14. DOM objects
    • All elements present in the XML document including their contents is accessed using the DOM tree. In the DOM tree the contents can be added, modified and deleted
    • The characteristics of a node tree are:
      • The top node represent the root.
      • A node has one parent node except root.
      • A node can have many children
      • A node with no child node is known as the leaf node.
      • Nodes having same parent node are known as siblings.
    Create by ChungLD faculty /31 Click and see
  • 15. Creation of XML Document Object
    • Create DOM
    • Read all xmll
    Create by ChungLD faculty /31
  • 16. Traversing a DOM Tree using Element Object
    • An element is a Node object and hence inherits the properties and methods of the Node interface. The method getElementsByTagName() returns a nodeList of the elements and the length() method can be used to loop through the list.
    Create by ChungLD faculty /31 Click and see
  • 17. Traversing a DOM Tree using Node Object
    • The node object represents a single node in the document tree. It is the basic data type of the DOM. There are children for all node types
    • There different node types are:
      • NODE_ELEMENT
      • NODE_ATTRIBUTE
      • NODE_TEXT
      • NODE_PROCESSING_INSTRUCTION
      • NODE_COMMENT
      • NODE_DOCUMENT
    Create by ChungLD faculty /31 Click and see
  • 18. Traversing a DOM Tree using NodeList
    • The NodeList object represents a collection of Node objects. Any alterations to the properties of node are reflected in the list. Individual nodes can be accessed using indexes as well as one can iterate through the collection.
    Create by ChungLD faculty /31 Click and see
  • 19. Traversing a DOM Tree using NameNodeMap Object
    • NameNodeMap object represents a collection of nodes that is accessed by name.
    Create by ChungLD faculty /31 Click and see
  • 20. Traversing a DOM Tree using Attribute Object
    • The Attribute of an element object is represented by the Attr interface and is defined in DTD. The Attr object is a node and inherits the properties and methods of the Node object. Attribute is a property of a child node and not a child node. An attribute does not have a parent node.
    Create by ChungLD faculty /31 Click and see
  • 21. XMLDOMParseError
    • The XMLDOMPaserError object is an extension to the W3C specification. It can be used to get detailed information on the last error that occurred while either loading or parsing a document. The XMLDOMParseError
    Create by ChungLD faculty /31
  • 22. Properties of XMLDOMParseError
      • errorCode
      • filepos
      • line
      • linepos
      • reason
      • srcText
    Create by ChungLD faculty /31
  • 23. SAX
    • Simple API for XML is an XML parser which parses an XML document and extracts information from the document.
    Create by ChungLD faculty /31
  • 24. XML Parsing using SAX
    • SAX is not a W3C standard and has well-deffined APIs for parsing XML document. SAX generates events as it reads through the document and the event handlers handle these events and provide access to the content of the XML document
    Create by ChungLD faculty /31
  • 25. The some common classes
    • ContentHandler calss is used for accessing the contents of the XML document
    Create by ChungLD faculty /31
  • 26. The DefaultHandler class
    • This is the default base class for SAX2 event handlers, it provides defalt implementations for all of the callbacks in the four core SAX2 handler classes: Entityresolver, DTDHandler, ContentHandler, ErrorHandler.
    Create by ChungLD faculty /31
  • 27. The XML Reader Interface
    • This is allows an application to set and query features and properties in the parser, to register event handlers for document processing and to begin parsing of ta document.
    Create by ChungLD faculty /31
  • 28. Microsoft XML DOM Objects
    • The Microsoft implementation of the XML Document Object Model(DOM) provides a set of classes and interface that map to the W3C DOM.
    Create by ChungLD faculty /31
  • 29. Properties
    • Properties
      • async:This property indicates whether asynchronous download is permitted or not. When set to true, the load() method returns control to the called document before the download is finished.
      • doctype: this property return an object representing the root element of the XML document.
      • implementation: this property return an implementation object that handles this document.
      • nodeName: this property returns a read-only property that returns a string containing the Node’s name depending on the type of Node
    Create by ChungLD faculty /31
  • 30. Event
    • ondataavailable:is raised when new data is available
    • ontransformnode: is raised before a stylesheet is applied to a node.
    Create by ChungLD faculty /31
  • 31. Method Create by ChungLD faculty /31 Click and see
  • 32. Properties and Method of an XMLDOMNode object
    • Properties
      • namespaceURI
      • parsed
      • xml
      • nodeName
      • nodeType
    • Method
      • hasChildNodes
      • insertBefore(child1,child2)
      • replaceChild(child1,child2)
      • removeChild(child)
      • appendChild(newChild)
    Create by ChungLD faculty /31 Click and see
  • 33. Properties and method of an XMLDOMNodeList
    • Properties
      • lengthproperty
    • Method
      • item
      • nextNode
      • reset
    Create by ChungLD faculty /31 Click and see
  • 34. XMLDOMNamedNodeMap
    • Properties
      • length returns the number of nodes in the map
    • Methods
    Create by ChungLD faculty /31 Click and see
  • 35. Summary and workshop Create by ChungLD faculty /31

×