Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML Session 3 Data Islands Document Object Model ParsingNamespaces.

Similar presentations


Presentation on theme: "XML Session 3 Data Islands Document Object Model ParsingNamespaces."— Presentation transcript:

1 XML Session 3 Data Islands Document Object Model ParsingNamespaces

2 Data islands XML embedded in HTML page XML embedded in HTML page Uses unofficial tag in HTML Uses unofficial tag in HTML Example: Example: External file: External file: XML-ers Frank Reminder Don't forget about the assignment!

3 Binding XML data to HTML Remember our CD collection (cd_catalogue.xml)? Remember our CD collection (cd_catalogue.xml)?(cd_catalogue.xml)? Here is how it could be used as a data island: Here is how it could be used as a data island: The result: (cd_catalogue.htm) The result: (cd_catalogue.htm)(cd_catalogue.htm)

4 Document Object Model What is a DOM? What is a DOM? In general, a DOM describes the structure of a document in Object terminology: In general, a DOM describes the structure of a document in Object terminology: The XML Document Object Model (XML DOM) defines a standard way for accessing and manipulating XML documents. The XML Document Object Model (XML DOM) defines a standard way for accessing and manipulating XML documents. The DOM presents an XML document as a tree structure, and gives access to the structure through a set of objects. The DOM presents an XML document as a tree structure, and gives access to the structure through a set of objects. To do this you need a parser. You can use a variety of languages. To do this you need a parser. You can use a variety of languages. Example of the DOM being applied to, and unpacking (parsing), a simple XML file, using Javascript: Example of the DOM being applied to, and unpacking (parsing), a simple XML file, using Javascript:using Javascriptusing Javascript Example of parsing the node tree using VBScript: Example of parsing the node tree using VBScript:VBScript Root/Parent Root/Parent object (e.g. Browser window) Child object (e.g. Graphic) Child object (e.g. Text)

5 Namespaces This piece of XML carries information about fruit in a table: This piece of XML carries information about fruit in a table: This piece of XML carries information about furniture: This piece of XML carries information about furniture: This poses a problem, because they share the same namespace. This poses a problem, because they share the same namespace. Apples Pears Bananas Ikea Sven Coffee Table 80 120

6 Namespaces We could avoid this by providing a prefix to disambiguate the element names: We could avoid this by providing a prefix to disambiguate the element names: … which would appear to solve the problem. … which would appear to solve the problem. Apples Pears Bananas Ikea Sven Coffee Table 80 120 However!

7 Namespaces All this prefixing is clumsy, and could lead to errors. All this prefixing is clumsy, and could lead to errors. Why not associate each namespace with an unambiguous identifier? Why not associate each namespace with an unambiguous identifier? Yes, it’s a URL – but it doesn’t have to point to a real resource. Yes, it’s a URL – but it doesn’t have to point to a real resource. Apples Bananas African Coffee Table 80 120


Download ppt "XML Session 3 Data Islands Document Object Model ParsingNamespaces."

Similar presentations


Ads by Google