Web-based Programming Lanjut Pertemuan 9 Matakuliah: M0492 / Web-based Programming Lanjut Tahun: 2007.

Slides:



Advertisements
Similar presentations
XML-XSL Introduction SHIJU RAJAN SHIJU RAJAN Outline Brief Overview Brief Overview What is XML? What is XML? Well Formed XML Well Formed XML Tag Name.
Advertisements

XML IV. The Document Object Model The Document Object model is a hierarchical structure of an XML document. It provides a means for accessing, and manipulating.
An Introduction to XML Based on the W3C XML Recommendations.
3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures.
CS 898N – Advanced World Wide Web Technologies Lecture 21: XML Chin-Chih Chang
XHTML1 Building Document Structure. XHTML2 Objectives In this chapter, you will: Learn how to create Extensible Hypertext Markup Language (XHTML) documents.
Document Type Definitions
Introduction to XLink Transparency No. 1 XML Information Set W3C Recommendation 24 October 2001 (1stEdition) 4 February 2004 (2ndEdition) Cheng-Chia Chen.
Sistemi basati su conoscenza XML Prof. M.T. PAZIENZA a.a
XML(EXtensible Markup Language). XML XML stands for EXtensible Markup Language. XML is a markup language much like HTML. XML was designed to describe.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
Tutorial 11 Creating XML Document
XML Primer. 2 History: SGML vs. HTML vs. XML SGML (1960) XML(1996) HTML(1990) XHTML(2000)
Introduction to XML Extensible Markup Language
Document Type Definitions. XML and DTDs A DTD (Document Type Definition) describes the structure of one or more XML documents. Specifically, a DTD describes:
XP New Perspectives on XML Tutorial 3 1 DTD Tutorial – Carey ISBN
XML introduction to Ahmed I. Deeb Dr. Anwar Mousa  presenter  instructor University Of Palestine-2009.
XP Tutorial 9New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with XHTML Creating a Well-Formed Valid Document Tutorial 9.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 XML Taken from Chapter 7.
HTML DOM.  The HTML DOM defines a standard way for accessing and manipulating HTML documents.  The DOM presents an HTML document as a tree- structure.
XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.
JS: Document Object Model (DOM)
XML eXtensible Markup Language by Darrell Payne. Experience Logicon / Sterling Federal C, C++, JavaScript/Jscript, Shell Script, Perl XML Training XML.
XML CPSC 315 – Programming Studio Fall 2008 Project 3, Lecture 1.
Representing Web Data: XML CSI 3140 WWW Structures, Techniques and Standards.
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
1/14 ITApplications XML Module Session 2: Using and Creating XML Documents.
Introduction to XML. What is XML? Extensible Markup Language XML Easier-to-use subset of SGML (Standard Generalized Markup Language) XML is a.
XHTML1 Building Document Structure Chapter 2. XHTML2 Objectives In this chapter, you will: Learn how to create Extensible Hypertext Markup Language (XHTML)
What is XML?  XML stands for EXtensible Markup Language  XML is a markup language much like HTML  XML was designed to carry data, not to display data.
Introduction to XML Extensible Markup Language. What is XML XML stands for eXtensible Markup Language. A markup language is used to provide information.
 XML is designed to describe data and to focus on what data is. HTML is designed to display data and to focus on how data looks.  XML is created to structure,
Session IV Chapter 9 – XML Schemas
Processing of structured documents Spring 2002, Part 2 Helena Ahonen-Myka.
Tutorial 1: XML Creating an XML Document. 2 Introducing XML XML stands for Extensible Markup Language. A markup language specifies the structure and content.
1 Tutorial 13 Validating Documents with DTDs Working with Document Type Definitions.
1 Dr Alexiei Dingli XML Technologies XML Advanced.
How do I use HTML and XML to present information?.
XML Documents Chao-Hsien Chu, Ph.D. School of Information Sciences and Technology The Pennsylvania State University Elements Attributes Comments PI Document.
Introduction to XML This presentation covers introductory features of XML. What XML is and what it is not? What does it do? Put different related technologies.
XML Instructor: Charles Moen CSCI/CINF XML  Extensible Markup Language  A set of rules that allow you to create your own markup language  Designed.
Lecture 16 Introduction to XML Boriana Koleva Room: C54
Accessing Data Using XML CHAPTER NINE Matakuliah: T0063 – Pemrograman Visual Tahun: 2009.
XML EXtensible Markup Language. Agenda Introduction to XML XML Rules XML Elements XML Attributes XML Validation XML Exercises XML Namespaces XML CDATA.
1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has been used to create a wide variety of different markup.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Understanding How XML Works Ellen Pearlman Eileen Mullin Programming the.
XML Introduction. What is XML? XML stands for eXtensible Markup Language XML stands for eXtensible Markup Language XML is a markup language much like.
What it is and how it works
XML Design Goals 1.XML must be easily usable over the Internet 2.XML must support a wide variety of applications 3.XML must be compatible with SGML 4.It.
C# and Windows Programming XML Processing. 2 Contents Markup XML DTDs XML Parsers DOM.
Introduction to XML February 07, From HTML to XML As mentioned in previous classes, if you know HTML, then you already know XML… really! In this.
1 Dr Alexiei Dingli XML Technologies SAX and DOM.
Introduction to the Document Object Model Eugenia Fernandez IUPUI.
Well Formed XML The basics. A Simple XML Document Smith Alice.
When we create.rtf document apart from saving the actual info the tool saves additional info like start of a paragraph, bold, size of the font.. Etc. This.
What is XML? eXtensible Markup Language eXtensible Markup Language A subset of SGML (Standard Generalized Markup Language) A subset of SGML (Standard Generalized.
Introduction to DTD A Document Type Definition (DTD) defines the legal building blocks of an XML document. It defines the document structure with a list.
XML CSC1310 Fall HTML (TIM BERNERS-LEE) HyperText Markup Language  HTML (HyperText Markup Language): December  Markup  Markup is a symbol.
JS: Document Object Model (DOM) DOM stands for Document Object Model, and allows programmers generic access to: DOM stands for Document Object Model, and.
Tutorial 9 Working with XHTML. New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 2 Objectives Describe the history and theory of XHTML.
C Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Introduction to XML Standards.
Introduction to XML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
XML DOM Week 11 Web site:
XML Introduction to XML Extensible Markup Language.
Unit 4 Representing Web Data: XML
Introduction to the Document Object Model
Chapter 7 Representing Web Data: XML
DOM Document Object Model.
Allyson Falkner Spokane County ISD
Presentation transcript:

Web-based Programming Lanjut Pertemuan 9 Matakuliah: M0492 / Web-based Programming Lanjut Tahun: 2007

Bina Nusantara Extensible Markup Language (XML) XML XML vs HTML Tag and elements Schemas and DTDs (Document Type Definition) Namespace Document Object Model (DOM)

Bina Nusantara eXtensible Markup Language (XML) Marking up the document is the process of identifying certain areas of a document as having a special meaning. A Markup language is just a set of rules that define how we add meaning to areas of a document.

Bina Nusantara XML vs HTML XML is designed to describe the structure of text, not how it should be displayed. HTML is designed to describe how the text should be displayed. Here we have some text This is a heading This bit is normal text This is some bold text And finally some more normal text as HTML as XML

Bina Nusantara XML vs HTML In XML, the tags can be anything you like, and it is only how we use them that give them a meaning. XML is fairly readable, so using tag names that describe the contents is common sense White Johnson Green Marjorie

Bina Nusantara Tags and Elements If using XML to describe data, then it’s possible that some fields might contain no data. In this case the tags would be empty. Empty tags can be defined in: – With start and end tag – just an opening tag, but with a slash at the end Tags in XML are case sensitive, so the opening and closing tags must match in case. invalid XML tags:

Bina Nusantara Tags and Elements Root Tags This is defined as the outer tag, and an XML document can have only one root White Johnson Green Marjorie White Johnson Green Marjorie valid tags Invalid tags

Bina Nusantara Tags and Elements The Tag – not a true XML tag, but a special tag indicating special processing instructions. – This should be the first line of each XML document, can be used to identify version and language information. – This tag is also the place where you can define the language used in the XML data. – This is important if your data contains character that aren’t part of the standard English ASCII character set.

Bina Nusantara Tags and Elements LanguageCharacter Set Unicode (8 bit)UTF-8 Latin 1 (Western Europe, Latin America)ISO Latin 2 (Central/Eastern Europe)ISO Latin 3 (SE Europe)ISO Latin 4 (Scandinavia/Baltic)ISO Latin/CyrillicISO Latin/ArabicISO Latin/GreekISO Latin/HebrewISO Latin/TurkishISO Latin/Lappish/Nordic/EskimoISO JapaneseEUC-JP or Shift_JIS

Bina Nusantara Tags and Elements Attribute XML attribute must be enclosed in quotes. Special Character Special set of character cannot be used in normal XML strings. BOOK ISBN=“ ”>Professional Active Server Pages 3.0 CharacterMust be replaced by & & < < > > “ " ‘ &apos;

Bina Nusantara Schemas and DTDs Schema and DTDs are the flip side of the same coin. Both specify which elements are allowed in a document, and can turn a well-formed XML document into a valid XML document. DTD is a text file that defines the structure of an XML document. But DTD isn’t itself XML – it has a completely separate syntax. Schema is the structure that defines DTS should be XML too.

Bina Nusantara Schemas and DTDs This one is for the authors XML document, as generated from the pubs database. The + sign says ‘one or more’. Each AUTHOR element is made up from nine other elements. Each of this sub- elements contains character data (CDATA)

Bina Nusantara Schemas and DTDs Two real flaws with DTDs: – they aren’t XML – You cannot specify the data types – such as integer, date, and so on – for each element. CDATA simply means that an element contains just character data, and doesn’t identify the actual type of the element’s contents.

Bina Nusantara Schemas and DTDs If we convert the DTD into a schema it would be something like:

Bina Nusantara Schemas and DTDs With the addition of data types we’d get: This schema now details not only the allowable elements, but also their data types.

Bina Nusantara Namespaces One problem with XML is that you can give an element almost any name you want. – There’s quite a good chance that you’ll pick the same name as someone else – Or even use the same name to mean different things in different XML documents. Yes This is taken from the authors table in pubs, and indicates the author is a contracted author. F:/contacts/1999.doc This contract element identifies the document that contains the contract This isn’t a problem while these documents stay separated. But if you combine the two documents, use the namespace to identify to which document the contract element belongs to.

Bina Nusantara Namespaces Namespaces are added to XML document by defining the xmlns (XML Name Space) attribute in the root tag, which requires a Uniform Resource Identifier (URI). URI is simply a name that can uniquely identify the namespace. <Authors xmlns:pubs=“ xmlns:wrox=“ White Johnson Yes F:/contacts/Johnson1999.doc

Bina Nusantara Document Object Model (DOM) The Document Object Model is an API for HTML and XML documents, and the way they can be accessed. DOM defines a standard way in which we can access and manipulate the XML structure White Johnson Green Marjorie The XML documents are hierarchical by nature – always have a top-level, or root element, and then child elements.

Bina Nusantara Document Object Model (DOM) The previous document could be represented as: Authors Author au_id au_lname au_fname In DOM terms, these elements are also nodes. A node just represent a generic element in this tree-type structure.

Bina Nusantara Document Object Model (DOM) Base Objects To represent this hierarchical nature, the DOM provides a whole set of objects, methods, and properties that allow us to manipulate the DOM. ObjectDescription Node A single node in the hierarchical NodeList A collection of nodes NamedNodeMap A collection of nodes allowing access by name as well as index

Bina Nusantara Document Object Model (DOM) PropertyDescription ChildNodes Returns a NodeList containing the children of the node. firstChild Returns the first child of the current node. lastChild Returns the last child of the current node. parentNode Returns the parent node of the current node. previousSibling Returns the previous sibling, i.e., the previous node at the same level in the hierarchy. nextSibling Returns the next sibling, i.e., the next node at the same level in the hierarchy. nodeName The name of the node nodeValue The value of the node.

Bina Nusantara Document Object Model (DOM) Authors Author au_idau_lnameau_fname childNodes parentNode firstChild previousSibling nextSibling parentNode lastChild CodePoints to nodRoot.childNodes(0)Author nodRoot.childNodes(0).firstChildau_id nodRoot.childNodes(0).firstChild.nextSiblingau_lname nodRoot.childNodes(0).firstChild.parentNodeAuthor nodRoot.childNodes(0).firstChild.nextSibling.parentNodeAuthor So, let’s assume we have a node object called nodRoot pointing to Authors:

Bina Nusantara Document Object Model (DOM) Specific DOM Objects ObjectDescription DocumentThe root object for an XML document DocumentTypeInformation about the DTD or schema associated with the XML document. Equivalent to !DOCTYPE in a DTD. DocumentFragmentA lightweight copy of the Document, useful for temporary storage or document insertions. ElementAn XML element Attribute or AttrAn XML attribute EntityA parsed or unparsed entity. Equivalent to !ENTITY in a DTD. EntityReferenceAn entity reference NotationA notation. Equivalent to !NOTATION in a DTD. CharacterDataThe base object for text information in a document CDATASectionUnparsed character data. Equivalent to !CDATA in a DTD TextThe text contents of an element or attribute node CommentAn XML comment element ProcessingInstructionA processing instruction, as held in the section ImplementationApplication specific implementation details.

Bina Nusantara  DOMExample.html    var i;  var curNode;  var xmlDocument = new ActiveXObject("Microsoft.XMLDOM");  xmlDocument.load("authors.xml");  var element = xmlDocument.documentElement;  document.writeln("The root node of the document is: " + element.nodeName + " ");  document.writeln(" Its child elements are:");  for(i = 0; i < element.childNodes.length; i++) {  var curNode = element.childNodes.item(i);  document.writeln(" " + curNode.nodeName + " ");}  var currentNode = element.firstChild;  document.writeln(" The first child of the root node is: " + currentNode.nodeName + " ");  document.writeln(" Its child elements are:");  for(i = 0; i < currentNode.childNodes.length; i++) {  curNode = currentNode.childNodes.item(i);  document.writeln(" " + curNode.nodeName + " - value : " + curNode.firstChild.nodeValue +" "); }  var nextSib = currentNode.nextSibling;  document.writeln(" The next sibling is: " + nextSib.nodeName + " ");  document.writeln(" Its child elements are:");  for(i = 0; i < nextSib.childNodes.length; i++) {  curNode = nextSib.childNodes.item(i);  document.writeln(" " + curNode.nodeName +" - value : " + curNode.firstChild.nodeValue +" "); } 

Bina Nusantara Document Object Model (DOM)

Bina Nusantara Document Object Model (DOM) Traversing the DOM – XML is a relatively new area. many browsers don’t support the handling of XML data. – IE 5.0 or above is really the browser that good support for it. – You have to decide whether you want to send the XML data to the browser, or you want to process the XML in ASP pages and send pure HTML up to the browser. This depends upon your target audience.

Bina Nusantara   TraverseXML.html   var g_strNodeTypes = new Array ('','ELEMENT (1)','ATTIBUTE (2)','TEXT (3)','CDATA SECTION (4)',  'ENTITY REFERENCE (5)', 'ENTITY (6)', 'PROCESSING INSTUCTION (7)',  'COMMENT (8)', 'DOCUMENT (9)', 'DOCUMENT TYPE (10)',  ‘DOCUMENT FRAGMENT (11)', 'NOTATION (12)');  function showChildNodes(nodNode, intLevel)  {  var strNodes = ''; // string containing the nodes information  var intCount = 0;// count of the nodes  var intNode = 0;// current node number  var nodAttrList;// node list of the attributes for a node  // Get the values for this node  for (var i=0; i<intLevel; i++)  strNodes = strNodes + ' ';  strNodes += ' ' + nodNode.nodeName + ' Type: ' + g_strNodeTypes[nodNode.nodeType] +' Value: ' + nodNode.nodeValue  + ' ';  // check there are some sttribute  nodAttrList = nodNode.attributes;  if(nodAttrList != null)  {  intCount = nodAttrList.length;  if(intCount>0)  {  // for each attribute, display the attribute information  for (intAttr=0; intAttr<intCount; intAttr++)  strNodes += ' ' + nodAttrList(intAttr).nodeName + ' Type: ' + g_strNodeTypes[nodAttrList(intAttr).nodeType] + ' Value: ' + nodAttrList(intAttr).nodeValue + ' ';  }  }

Bina Nusantara  //check for any child nodes  intCount =nodNode.childNodes.length;  if (intCount > 0)  //for each child node, display the node, attributes, and its child node information  for(intNode = 0; intNode <intCount; intNode++ )  strNodes += showChildNodes(nodNode.childNodes(intNode), intLevel + 1);  return strNodes;  }  function start_traverse()  {  var domXMLData = new ActiveXObject("Microsoft.XMLDOM");  domXMLData = dsoData;  txtData.innerHTML = showChildNodes(domXMLData,0);  }     Traversing the Nodes in an XML Document    

Bina Nusantara Document Object Model (DOM)