Style Sheets: CSS and CSS2 W3C recommendation on Cascading Style - - PDF document

style sheets css and css2
SMART_READER_LITE
LIVE PREVIEW

Style Sheets: CSS and CSS2 W3C recommendation on Cascading Style - - PDF document

DHTML and DOM Venkat Subramaniam svenkat@cs.uh.edu 1 Style Sheets: CSS and CSS2 W3C recommendation on Cascading Style Sheet CSS level 1 specification allows expressing style of contents CSS level 2 specification goes further


slide-1
SLIDE 1

1

Venkat Subramaniam – svenkat@cs.uh.edu

DHTML and DOM

2

Venkat Subramaniam – svenkat@cs.uh.edu

Style Sheets: CSS and CSS2

  • W3C recommendation on Cascading Style

Sheet

  • CSS level 1 specification allows

expressing style of contents

  • CSS level 2 specification goes further into

– positioning – use of HTML 4.0 – defining additional tags

slide-2
SLIDE 2

3

Venkat Subramaniam – svenkat@cs.uh.edu

Positioning

  • HTML elements are positionable
  • You may specify where they should appear

– as part of the style – position attribute

  • position attribute may take

– absolute

  • Position based on or relative to the parent container. Natural

document flow ignored.

– relative

  • Position is relative to the normal document flow.

– static

  • element not positionable, maintains normal position.

4

Venkat Subramaniam – svenkat@cs.uh.edu

Positioning Context

  • Positioning context is a point which

corresponds to (0, 0) for an element

  • For the HTML document, it starts with the

top left corner of browser window (document area)

  • When you define a block level element, it

defines a new context for that element

– Every thing is now relative to this new context

  • You can define a new context by setting

the position attribute

slide-3
SLIDE 3

5

Venkat Subramaniam – svenkat@cs.uh.edu

Absolute vs. Relative

<HEAD><STYLE> SPAN.l1 {position:absolute; left:20; top:30} SPAN.l2 {position:relative; left:20; top:30} </STYLE></HEAD> <BODY> <DIV>Hello <SPAN class="l1">there</SPAN> <SPAN class="l2">!</SPAN> </DIV>

With no positioning

  • nly first Positioning

absolute positioning Moved with respect to where browser would have placed it otherwise 6

Venkat Subramaniam – svenkat@cs.uh.edu

Positioning Attributes

  • position

– style rule for a postionable element

  • left

– offset from left edge of positioning context to left edge of box

  • top

– offset from top edge of positioning context to top edge of box

  • width

– width of absolute positioned element’s content

  • height

– height of absolute positioned element’s content

  • clip

– viewable area shape, dimension of an absolute positioned element

  • verflow

– for handling contents that exceed height/ width

  • visibility

– says if element is visible or not

  • Z-index

– stacking order of a positionable element

slide-4
SLIDE 4

7

Venkat Subramaniam – svenkat@cs.uh.edu

DOM: Document Object Model

  • HTML documents are parsed and

displayed by browsers

  • Fonts and colors may be specified
  • To a certain extent position may be

specified

  • How about dynamically modifying the

contents on the front end?

  • DOM provides handled into the browser,

allowing us to access various components

  • f the document at run time

8

Venkat Subramaniam – svenkat@cs.uh.edu

Document Object Model

  • Document class represents an HTML document
  • Provides you a write method

– you can generate HTML dynamically on the client- side

  • Document’s properties

– alinkColor – anchors[ ] – applets[ ] – bgColor – cookie – Domain – embeds[ ] – fgColor – forms[ ] – images[] – lastModified – linkColor – links[] – referrer – title – URL – vlinkColor

slide-5
SLIDE 5

9

Venkat Subramaniam – svenkat@cs.uh.edu

Scripting Events

  • Various types of events are generated
  • Types of events depends on the

positionable element

  • Event handler may be specified as an

attribute of the element

  • For certain events, returning

– true will result in browser continuing with its usual behavior – false will result in browser ignoring the rest

  • f action

10

Venkat Subramaniam – svenkat@cs.uh.edu

Dynamic Techniques

  • DOM allows us to address elements
  • Event allows us to respond to activities
  • Scripts can effectively

– provide event handlers – access elements using DOM

  • Dynamic content generation on the front

end for data validation and varying presentation and style

slide-6
SLIDE 6

11

Venkat Subramaniam – svenkat@cs.uh.edu

DOM

  • Browser exposes the object model of the

document for you to manipulate

  • The Document Object Model

12

Venkat Subramaniam – svenkat@cs.uh.edu

The structure of a document

  • An XML document contains

– data and – information on the data (Meta information)

  • XML document contains

– the contents and – structure

  • What is the structure?

– the types of items it contains

  • elements, child-elements, attributes, content data

– relationship between these items

  • Which element is the parent of a child element
  • what are its attributes
slide-7
SLIDE 7

13

Venkat Subramaniam – svenkat@cs.uh.edu

Grove

  • Grove is an abstract model of a structure
  • It is the concept and representation of

the structure of an XML document

  • It represents a tree view of

– Elements

  • the child elements
  • the attributes

– their values

  • content data
  • etc.
  • Grove is a model not an API of any kind

– information on structure not mechanism to access it – various APIs used to access and manipulate these models

14

Venkat Subramaniam – svenkat@cs.uh.edu

Object Model

  • Methods, properties provided to access a

structure

  • The interface is the key

– Hides the details of structure from programmers

  • Interface based programming allows one

to

– Access the details of an abstraction – Without depending on the specifics of the abstraction

slide-8
SLIDE 8

15

Venkat Subramaniam – svenkat@cs.uh.edu

What is DOM?

  • How do you access an XML document?
  • Need to parse and extract information

among meta information

  • DOM is an interface/ API for such access

– Language and platform independent – Specification that may be implemented in any language

  • It provides the flexibility to read a

document, to modify, to search it, to add

  • n to it and remove from

16

Venkat Subramaniam – svenkat@cs.uh.edu

What does DOM provide?

  • If you were to deal with a document, you

are looking at the physical layout of its content

  • How many elements does it have?
  • How do you add an element?

– Read through all elements and get to the end and append!

  • How about a logical view of the

document?

– You can easily understand the structure – You can easily manipulate the structure using an interface/ API

slide-9
SLIDE 9

17

Venkat Subramaniam – svenkat@cs.uh.edu

Why use DOM?

  • DOM parses and builds all information

into memory

  • DOM

– Validates well-formedness and grammar

  • Using DOM to create a document guarantees

correctness of format

– Provides logical/ object view hiding the details

  • You can rely on the logical view rather than

reading through file structure and tags

– Helps it easy to manipulate the document

  • You don’t have to endure the pain of parsing
  • You can rely on API to read
  • Lets you delete arbitrary items from the document

18

Venkat Subramaniam – svenkat@cs.uh.edu

Drawbacks of DOM

  • DOM ends up taking more memory

– Much larger than the size of the document

  • Reads and builds information on the

entire document

  • Not efficient for lookup of subset of

information

  • Entire tree built, whether you need it or

not

slide-10
SLIDE 10

19

Venkat Subramaniam – svenkat@cs.uh.edu

API for DOM

  • DOM is a specification of Interface
  • Several APIs implement this interface
  • Comes in different flavors
  • Watch out for parsing large sized

documents

  • May take up too much memory to store

large documents

– Some implementations provide just-in-time extraction to manage large size data, at expense of additional seek and retrieval time

20

Venkat Subramaniam – svenkat@cs.uh.edu

DOM aids document interchange

  • Provides effective method to exchange

Platform independent self-describing data

  • Robustness and validation
  • Illustrates the relationship between data

elements that may not otherwise be

  • bvious

Application Application

slide-11
SLIDE 11

21

Venkat Subramaniam – svenkat@cs.uh.edu

DOM facilitates data archival

  • Text formed data can be easily archived,

parsed, compressed and transferred

  • The contents of a data store may be archived

for later use or reference purpose

  • Applications (like mail program) may use this

for archiving older mails/ records

  • Useful for initialization/ configuration

information as well

22

Venkat Subramaniam – svenkat@cs.uh.edu

Meaningful presentation of data

  • Client systems may interact with the

DOM nodes to decide and to eliminate information that may or may not be relevant

  • By packaging the information with the

semantics, client programs can put the information to better use

  • Systems may aid user with selective

utilization of information

slide-12
SLIDE 12

23

Venkat Subramaniam – svenkat@cs.uh.edu

A common data exchange “gateway”

App0 App1 App5 App3 App2 App4 App0 App1 App5 App3 App2 App4

DOM

XML

24

Venkat Subramaniam – svenkat@cs.uh.edu

W3C’s DOM

  • “…

platform- and language-neutral interface that will allow programs and scripts to dynamically access and update the content, structure and style of documents”

  • Level 0

– Functionality of Netscape 3.0 and IE 3.0

  • Level 1

– Navigation and manipulation of HTML and XML doc – Oct. 1 1998

  • Level 2

– Support for namespaces, plus changes to interfaces – Nov. 13, 2000

  • Level 3

– Work under progress

slide-13
SLIDE 13

25

Venkat Subramaniam – svenkat@cs.uh.edu

The Tree Model

  • XML by nature provides relationships

– Parent child relationship

  • This ideally falls into a tree model
  • Parent nodes connecting to child nodes

gives logical view of data

– Easy to conceptualize – Easy to abstract and model

Parent Child Child Nodes

26

Venkat Subramaniam – svenkat@cs.uh.edu

The Tree Model as seen from IE

slide-14
SLIDE 14

27

Venkat Subramaniam – svenkat@cs.uh.edu

Node and Node Types

  • A Node is a base type that is a generic

node in the DOM Tree view model

  • Several types of specific node types

exists

  • You will never create node of simply the

type Node

  • You may treat all nodes as type Node,

however

28

Venkat Subramaniam – svenkat@cs.uh.edu

Document Node Types

  • Document

– The master node – Parent node representing the document as a whole – Does not represent any specific piece of XML data – Allows creation and insertion of other nodes – Only one can exists in an XML document

slide-15
SLIDE 15

29

Venkat Subramaniam – svenkat@cs.uh.edu

NodeList Node Type

  • NodeList

– Holds a collection of child nodes – Can provide information about child nodes

  • like how many is contained

– Main purpose is to provide information and access to child nodes

Parent Child Child NodeList Child Child Parent Conceptual Model DOM Model

30

Venkat Subramaniam – svenkat@cs.uh.edu

NamedNodeMap Node Type

  • Much like the NodeList in functionality
  • Provides the ability to access child nodes

by name

  • Needed for accessing attributes

– Typically attributes are lookup by their names

  • Used to hold attribute nodes
slide-16
SLIDE 16

31

Venkat Subramaniam – svenkat@cs.uh.edu

Element Node Type

  • Element node represents an element in

XML doc

  • Each child element has a parent element

node

– Except topmost element node whose parent is the Document node

  • Each element may have optionally child

elements

  • Top most element is given special name

– documentElement

32

Venkat Subramaniam – svenkat@cs.uh.edu

Text Node Type

  • Represent the text contained within

element tags

  • This is what makes the content of the

element

– The PCDATA types

slide-17
SLIDE 17

33

Venkat Subramaniam – svenkat@cs.uh.edu

Attr Node Type

  • Generally specified within element
  • Represents attributes within scope of

elements

  • Also used in Entity and Notation nodes

34

Venkat Subramaniam – svenkat@cs.uh.edu

Tree Model with Elements, Attributes

  • Consider:

<Catalog> <Book material="paper" cover="paperback"> <Title>Applied XML</Title>

Document Node NodeList Element Node {Catalog} NodeList Element Node {Book} NameNodeMap Node Attribute Node {material} Attribute Node {cover} NodeList NodeList Text Node {paper} Text Node {paperback} NodeList Text Node {Appli…} NodeList Element Node {Title}

slide-18
SLIDE 18

35

Venkat Subramaniam – svenkat@cs.uh.edu

CDATA Section Node Type

  • Similar in nature to the Text node
  • Contains data that does not contain any

markup

  • Arbitrary non parsed text makes up this

36

Venkat Subramaniam – svenkat@cs.uh.edu

DocumentType Node Type

  • This represents a subset of what you put

into DTD

  • This object provides you access to the

DTD of a doc

  • Only ENTITY and NOTATION of DTD

exposed

– Known limitation of DOM

  • Child of the Document node
  • Parent to Entity node and Notation node
slide-19
SLIDE 19

37

Venkat Subramaniam – svenkat@cs.uh.edu

EntityReference Node Type

  • EntityReference node represents a

reference to an entity that is declared in DTD

  • It contains a Text node
  • However

– Text nodes under EntityReferences are read-

  • nly

– Pretty much use less since you can’t change this

38

Venkat Subramaniam – svenkat@cs.uh.edu

A few other Node Types

  • ProcessingInstruction

– Represents a PI in a document – This is a child of the Document node

  • Comment

– Represents a comment node

  • DocumentFragment

– Stripped down version of Document node – Used as place holder when moving nodes around

  • Simply temporary storage of nodes to be

reinserted into the tree

slide-20
SLIDE 20

39

Venkat Subramaniam – svenkat@cs.uh.edu

DOM API

  • DOM API comes in different languages

and flavors

  • We will see the DOM API using JavaScript
  • Other scripting languages may also be

used

  • The API pretty much maps over to other

scripting languages and programming languages

40

Venkat Subramaniam – svenkat@cs.uh.edu

var in JavaScript

  • JavaScript is not a strongly typed

language

  • var refers to a variable that may be

assigned any variable or object

  • It may be assigned just about any thing
  • f any type
  • In case of xml data island, the id

represents the Document node

slide-21
SLIDE 21

41

Venkat Subramaniam – svenkat@cs.uh.edu

Data Island Options

  • In an HTML file you may

– Contain an XML file within – Refer to an external XML file

<XML ID="xmlID101"> <!-- … content of the XML file> </XML>

  • Multiple data islands may appear with

unique IDs

  • var docNode = anID;

– Refers to a DOM document node object

42

Venkat Subramaniam – svenkat@cs.uh.edu

Accessing XML DOM Node

  • Three ways to access an XML DOM node

– The ID represents a document Node

  • var docNode = xmlID101;

– The ID treated as HTML object model’s all collection

  • var docNode = document.all("xmlID101");

– You may obtain using the XMLDocument property

  • var docNode =

document.all("xmlID101").XMLDocument;

slide-22
SLIDE 22

43

Venkat Subramaniam – svenkat@cs.uh.edu

Using an independent XML DOC

  • IE5 provides an XML parser as an ActiveX
  • bject
  • The CLSID for the parser maps to the program

alias

– "microsoft.xmldom"

  • You may create an XML Parse object by calling

– var parse = new ActiveXObject("microsoft.xmldom");

  • You may want to set parse.async = false to disable

synchronous downloading

  • You may call load method to load your XML doc
  • Then use the functions on the Document object

44

Venkat Subramaniam – svenkat@cs.uh.edu

Accessing an external XML Doc

  • You may place a XML within HTML

– data island

  • You may also refer to an XML file outside
  • Simply

– invoke the parser – ask it to load/ parse external file

  • The document node object now refers to

parsed external XML document

slide-23
SLIDE 23

45

Venkat Subramaniam – svenkat@cs.uh.edu

Displaying Document Node Info

  • The xml id represents the document node
  • We can create a variable that refers to

this id

  • This is a reference or handle to a

Document node object

  • You can now call documentElement to get

to the root element

  • nodeName will tell you the name of the

node

46

Venkat Subramaniam – svenkat@cs.uh.edu

Classes in DOM API

Node NodeList NamedNodeMap DOMException DOMImplementation DocumentFragment Document CharacterData Attribute Element DocumentType Notation Entity EntityReference ProcessingInstruction Text Comment CDATASection

slide-24
SLIDE 24

47

Venkat Subramaniam – svenkat@cs.uh.edu

Node Property: nodeName

– String: name of node: effect depends on type of node

  • Document

# document

  • Element

tag name

  • Attribute

attribute name

  • Text

# text

  • CDATASection

# cdata-section

  • Comment

# comment

  • Entity

entity name

  • Notation

notation name

  • EntityReference

name of entity reference

  • ProcessingInstructiontarget
  • DocumentType

document types name

  • DocumentFragment

# document-fragment

48

Venkat Subramaniam – svenkat@cs.uh.edu

Node Property: nodeValue

– String: data of the node: effect depends on type of node

  • Attribute

attribute value

  • ProcessingInstruction

text (following target)

  • Comment

comment text

  • Text

text

  • CDATASection

text

  • Other nodes

null

slide-25
SLIDE 25

49

Venkat Subramaniam – svenkat@cs.uh.edu

Node Property: nodeType

– int: type of

  • The type of node and the corresponding int are
  • 1

Element

  • 2

Attribute

  • 3

Text

  • 4

CDATASection

  • 5

EntityReference

  • 6

Entity

  • 7

ProcessingInstruction

  • 8

Comment

  • 9

Document

  • 10 DocumentType
  • 11 DocumentFragment
  • 12 Notation

50

Venkat Subramaniam – svenkat@cs.uh.edu

Node Property:

  • wnerDocument
  • Docum entNode: Document node in

which the current node resides

  • Returns access to the highest level parent
  • f any node
  • Very convenient for

– creating other nodes – accessing top level details

slide-26
SLIDE 26

51

Venkat Subramaniam – svenkat@cs.uh.edu

Node Property: Accessing Other Nodes

  • childNodes

– NodeList: holds collection of children nodes – If node does not have any children

  • then the returned NodeList will indicate a length of zero
  • parentNode

– Node: node of the parent

  • attributes

– Nam edNodeMap: holds all attributes of given node

  • firstChild : Node
  • lastChild : Node
  • previousSibling : Node
  • nextSibling : Node

52

Venkat Subramaniam – svenkat@cs.uh.edu

Node Methods

  • Calling on non-supporting node type causes error
  • insertBefore(newChild: Node, refChild: Node) : Node

– Inserts before refChild. At end if refChild null – DOMException thrown in case of invalid node type,…

  • replaceChild(newChild: Node, oldChild: Node) : Node
  • removeChild(oldChild: Node) : Node
  • appendChild(newChild: Node) : Node

– If newChild is located somewhere else in tree

  • it is first removed from that location
  • then added to current list
  • hasChildNodes() : Boolean
  • cloneNode(deep: Boolean) : Node
slide-27
SLIDE 27

53

Venkat Subramaniam – svenkat@cs.uh.edu

  • normalize : void

– moved from Element in Level 2

  • isSupported(feature : String , version : String)

: boolean

  • hasAttributes() : boolean
  • namespaceURI : String
  • prefix : String
  • localName : String

Node Properties and Methods (Level 2)

54

Venkat Subramaniam – svenkat@cs.uh.edu

Document Property: documentElement

– Elem ent node: highest level element in the document

  • This returns the top most element within

the XML document

  • The given node is of type Element node
slide-28
SLIDE 28

55

Venkat Subramaniam – svenkat@cs.uh.edu

Document Property: doctype

– Docum entType node: One that holds subset of DTDs

  • Returns the DocumentType object which

holds a subset of the DTDs in the document

56

Venkat Subramaniam – svenkat@cs.uh.edu

Document Property: implementation

– DOMI m plem entation node: the DOM implemetation

  • DOMImplementation provides details

about version

  • Mechanism to perform version checking
  • n the doc
slide-29
SLIDE 29

57

Venkat Subramaniam – svenkat@cs.uh.edu

Document Methods

  • createElement(tagName: String) : Element
  • createDocumentFragment() :

DocumentFragment

  • createTextNode(data: String) : Text
  • createComment(data: String) : Comment
  • createCDATASection(data: String) : CDATASection
  • createProcessingInstruction(

target: String, data: String) :

ProcessingInstruction

  • createAttribute(name: String) : Attribute
  • createEntityReference(name: String) :

EntityReference

  • getElementsByTagName(tagName: String) :

NodeList

58

Venkat Subramaniam – svenkat@cs.uh.edu

Document Methods (Level 2)

  • importNode(importedNode : Node, deep :

boolean) : Node

  • createElementNS(namespaceURI : String,

qualifiedName : String) : Element

  • createAttributeNS(namespaceURI :

String, qualifiedName : String) : Attr

  • getElementByTagNameNS(namespaceURI

: String, localName : String) : NodeList

  • getElementByID(elementID : String) :

Element

slide-30
SLIDE 30

59

Venkat Subramaniam – svenkat@cs.uh.edu

Element Property: tagName

  • String: represents the tag name of the

element

  • This information is the same as the one

returned by nodeName on a Node

  • For an Element you may use either one

interchangeably

60

Venkat Subramaniam – svenkat@cs.uh.edu

Element Methods

  • getAttribute(name: String): String
  • setAttribute(name: String, value: String)
  • removeAttribute(name: String)
  • getAttributeNode(name: String) : Attribute
  • removeAttributeNode(oldAttr: Attribute) :

Attribute

  • setAttributeNode(newAttr: Attribute) : Attribute
  • getElementsByTagName(name: String) :

NodeList

– Unlike Document’s method, returns only elements within the sub-tree of current element node, not whole doc

slide-31
SLIDE 31

61

Venkat Subramaniam – svenkat@cs.uh.edu

  • getAttributeNS(namespaceURI : String, localName :

String) : String

  • setAttributeNS(namespaceURI : String, qualifiedName :

String) : void

  • removeAttributeNS(namespaceURI : String,

qualifiedName : String) : void

  • getAttributeNodeNS(namespaceURI : String, localName

: String) : Attr

  • setAttributeNodeNS(newAttr : Attr) : Attr
  • getElementsByTagNameNS(namespaceURI : String,

localName : String) NodeList

  • hasAttribute(name : String) : boolean
  • hasAttributeNS(namespaceURI : String, localName :

String) : boolean

Element Methods (Level 2)

62

Venkat Subramaniam – svenkat@cs.uh.edu

Attribute Properties

  • name: String
  • specified: Boolean

– true if this attribute was specified in the XML document

  • value: String
  • ownerElement: Element

– Introduced in DOM Level 2 – gives the element to which this attribute belongs

slide-32
SLIDE 32

63

Venkat Subramaniam – svenkat@cs.uh.edu

NodeList Properties and Methods

  • length: unsigned long int
  • item(index: unsigned long integer value)

– Zero based index is used

  • On IE5, a shortcut

theNode.childNodes(index) may be used instead of theNode.childNodes.item(index)

64

Venkat Subramaniam – svenkat@cs.uh.edu

NamedNodeMap Properties & Methods

  • length: unsigned long integer
  • getNamedItem(name: String) : Node
  • setNamedItem(node: Node) : Node

– If another node with name same as given node exists

  • replaces that node

– Exception thrown if

  • given node created in another document(OK in IE5)
  • if read-only or given node in another element
  • removeNamedItem(name: String) : Node
  • item(index: unsigned long integer value) : Node
  • Level 2 methods

– getNamedItemNS(namespaceURI : String, localName : String) : Node – setNamedItemNS(arg : Node) : Node – removeNamedItemNS(namespaceURI : String, localName : String) : Node

slide-33
SLIDE 33

65

Venkat Subramaniam – svenkat@cs.uh.edu

CharacterData Properties, Methods

  • data: String
  • length: Integer
  • substringData( offset: unsigned long, count: unsigned long

) : String

  • appendData(appendString: String)
  • insertData(offset: unsigned long,

newString: String)

  • deleteData(offset: unsigned long,

count: unsigned long)

  • replaceData( offset: unsigned long, count: unsigned long,

data: String) 66

Venkat Subramaniam – svenkat@cs.uh.edu

Text Methods

  • splitText(offset: long) : Text
  • Produces two text nodes from the text

node on which it is called

  • First text node has characters from index

0 upto given offset

  • Second text node has characters from
  • ffset point to the original length – 1
slide-34
SLIDE 34

67

Venkat Subramaniam – svenkat@cs.uh.edu

CDATASection & Comment

  • CDATASection

– is identical to Text as it derives from it – no new properties or methods

  • Comment

– is identical to CharacterData – no new properties or methods

68

Venkat Subramaniam – svenkat@cs.uh.edu

DocumentType properites, Methods

  • name: String

– Name of the root document that follows DOCTYPE – Read only access provided to this

  • entities: NamedNodeMap
  • notations: NamedNodeMap
  • No methods to manipulate any of these
slide-35
SLIDE 35

69

Venkat Subramaniam – svenkat@cs.uh.edu

Entity/ Notation properties, Methods

  • systemid: String

– This is what follows the SYSTEM declaration – If not present, will return null

  • publicid: String

– This is what follows the PUBLIC declaration – If not present, will return null

  • The above tw o m ethods are also for

Notation

  • notationName: String

– Name of notation for unparsed entities (null for parsed ones)

70

Venkat Subramaniam – svenkat@cs.uh.edu

EntityReference, ProcessingInstruction

  • EntityReference does not add any more

than Node

  • ProcessingInstruction

– target: String – data: String

slide-36
SLIDE 36

71

Venkat Subramaniam – svenkat@cs.uh.edu

DOMImplementation Methods

  • hasFeature(feature: String,

version: String) : Boolean

  • If specified version exists for the specified

feature, return true; otherwise returns false

  • Valid values as of now are

– HTML and XML – Current version of XML is 1.0

72

Venkat Subramaniam – svenkat@cs.uh.edu

DOMString

  • DOMString is really used to represent

String

  • Based on language, it will map to String,

BSTR, etc.

  • It represents a 16-bit unicoded entity

rather than a byte

slide-37
SLIDE 37

73

Venkat Subramaniam – svenkat@cs.uh.edu

DOMException

  • This is the exception class used in

methods that throw exceptions

  • This maps to language specifics, as well

74

Venkat Subramaniam – svenkat@cs.uh.edu

MS Extensions for DOM

  • Microsoft XML Parse provides extensions to the DOM

model by adding support for

– Data types support

  • Defines several data types like date, int, etc for validation

– Namespace support

  • You can request for qualified name, prefix, URI

– XSL support

  • transformNode() method applies XSL transformation

– Asynchronous downloads

  • async (enable/ disable async download)
  • readyState and parsed (describe state of document)
  • abort (abort async download and discard loaded document)

– Thread safety support (Free threaded and rental model)

  • Microsoft.FreeThreadedXMLDOM may be used to create ActiveX
  • bject

– xml property lets you persist XML tree

  • allows modification and save
slide-38
SLIDE 38

75

Venkat Subramaniam – svenkat@cs.uh.edu

MS DOM Interfaces

  • Similar to DOM interfaces, start with IXMLDOM

– Provides additional properties and methods

  • IXMLDOMNamedNodeMap, IXMLDOMNodeList
  • IXMLDOMParseError, IXMLDOMImplementation,

IXMLDOMHttpRequest

  • IXMLDOMNode

– IXMLDOMDocumentFragment – IXMLDOMAttribute – IXMLDOMElement – IXMLDOMDocument – IXMLDOMDocumentType – IXMLDOMNotation – IXMLDOMEntity – IXMLDOMEntityReference – IXMLDOMProcessingInstruction – IXMLDOMCharacterData

  • IXMLDOMText, IXMLDOMCDATASection, IXMLDOMComment

Here we address Some of the interesting /important ones

76

Venkat Subramaniam – svenkat@cs.uh.edu

IXMLDOMNode’s xml

  • xml: String
  • This produces an XML document starting

from the current node

  • The XML document formed is useful for

saving an XML document that has been manipulated using DOM

slide-39
SLIDE 39

77

Venkat Subramaniam – svenkat@cs.uh.edu

IXMLDOMNode’s text

  • text: String
  • Contents of the node concatenated with

all the contents of the nodes found in the childNodes collection

  • For nodes with no children, simply

returns the value of that node

78

Venkat Subramaniam – svenkat@cs.uh.edu

IXMLDOMNode’s parsed

  • parsed: Boolean
  • Tells whether the node and its children

have been parsed

  • Useful in the case of asynchronous

loading of XML documents

slide-40
SLIDE 40

79

Venkat Subramaniam – svenkat@cs.uh.edu

IXMLDOMNode’s transformNode()

  • transformNode(stylesheet: Node): String
  • This methods applies the given stylesheet

transformation on the current node

  • The result String contains the

transformed XML

  • Pretty useful to apply one of select few

stylesheets on an XML document

80

Venkat Subramaniam – svenkat@cs.uh.edu

IXMLDOMDocument Properties

  • url: String

– If load() was used, this returns the URL location of doc

  • parseError: IDOMParseError

– Error object for this document

  • readyState: Long integer

– State of downloading and parsing progress – States are: UNINITIALIZED, LOADING, LOADED, INTERACTIVE, COMPLETED

  • async: Boolean

– true for asynchronous loading

  • validateOnParse: Boolean

– tells if the parser should check if the document conforms to DTD

  • preserveWhiteSpace: Boolean
  • resolveExternals: Boolean
slide-41
SLIDE 41

81

Venkat Subramaniam – svenkat@cs.uh.edu

IXMLDOMDocument Methods

  • load(url: String): Boolean
  • loadXML(xml: String): Boolean

– An XML document itself given as String, loaded, parsed

  • save(destination: String or IXMLDOMDocument
  • r

ASP Response object): integer

– Saves the DOM tree to specified location – Intended for use on the server – Browse security will limit its usage on client side

  • createNode(type: int, name: String,

nsURI: String): Node

  • nodeFromID(id: String): Node
  • abort()

82

Venkat Subramaniam – svenkat@cs.uh.edu

IXMLDOMNodeList Methods

  • nextNode() : Node

– Returns the first node first, subsequent nodes follows

  • reset()

– Reset the iterator like nextNode() method so the next call would start at first method again

slide-42
SLIDE 42

83

Venkat Subramaniam – svenkat@cs.uh.edu

IXMLDOMNamedNodeMap

  • getQualifiedItem(name: String,

nameSpace: String): Node

  • removeQualifiedItem(name: Stirng,

ns: String): Node

  • nextNode(): Node
  • reset()

84

Venkat Subramaniam – svenkat@cs.uh.edu

IDOMParseError

  • errorCode: Long integer

– Error code of last parsing error

  • url: String

– URL of the XML document with parsing error

  • Reason: String

– Reason for the last error

  • srcText: Long integer

– Returns line of text on which parse found error

  • line: Long integer

– Line number where parse found error

  • linePos: Long integer

– Column number of error location

  • filepos: Long integer

– Character position of error from beginning of document