Matakuliah Tahun : T0063 – Pemrograman Visual : 2009 Accessing Data Using XML CHAPTER NINE Introduction • The eXtensible Markup Language (XML) is a language used to represent data in a form that does not rely on any particular proprietary technology. • XML Schema provides a way of defining and validating XML documents. • eXtensible Stylesheet Language (XSL) and eXtensible Stylesheet Language Transforms (XSLT) is another useful technology associated with XML. Bina Nusantara University 2 Introduction (cont.) • This capability enables you to take a single XML document and transform it into a variety of different versions for specific uses. • A number of classes within Visual Basic .NET provide methods that work directly with XML. • Microsoft’s .NET initiative uses XML as its foundation data technology. Bina Nusantara University 3 Objectives • Understand what XML is and how it is used within business-to-business transactions. • Understand XML Schemas and XSL Transforms and how they are used within the context of XML. • Read and process data that are stored in an XML document. Bina Nusantara University 4 Objectives (cont.) • Read data from a relational database and transform them into their equivalent XML. • Transform one XML document into a new XML document using an XSLT document. Bina Nusantara University 5 9.1 An XML Primer • What is XML? – XML provides a technology-neutral way to represent data. – XML is rapidly becoming the data format “standard” for the exchange of data on the Internet. – Data content and data presentation are separate. – Data represent what is called a tree. Bina Nusantara University 6 9.1 An XML Primer (cont.) • XML Syntax – The language is case sensitive. – There is one and only one root node. – All elements have a start tag and an end tag. – Tags must be nested correctly. – Attributes must be quoted. • An XML document is well formed if you follow the above rules. Bina Nusantara University 7 9.1 An XML Primer (cont.) – Namespaces • A namespace defines a point of reference. – Change the element tag by adding a prefix and a colon to the tag. – Ex. <furn:table> and <tax:table>. • Can differentiate two tags within the same document. • Syntax: xmlns:name = “uri” • The uri (Uniform Resource Identifier) is a unique identifier. Bina Nusantara University 8 9.1 An XML Primer (cont.) – Document Prolog • Indicates that the document is XML as well as other things such as document type, entity definitions and other processing instructions. Bina Nusantara University 9 9.1 An XML Primer (cont.) • XML Schemas – Rules that define legal elements, tags, and content. – Used to determine the validity of a document. – Industry specific XML schemas are being developed. Bina Nusantara University 10 9.1 An XML Primer (cont.) • Styling XML – Extensible Stylesheet Language Transforms (XSLT) provide a way to transform one XML document to another XML document. Bina Nusantara University 11 9.2 Creating XML Documents and XML Schemas Using Visual Basic .NET • Creating an XML Schema – Add an XML Schema to a project by selecting Add New Item from the File menu. – Use tools from the Toolbox to create the schema. – Save the Schema definition. Bina Nusantara University 12 9.2 Creating XML Documents and XML Schemas Using Visual Basic .NET (cont.) • Creating an XML Document – Complete the examples listed below in your textbook: • Example 9.1 Using Simple and Complex Data Types in XML Schemas. • Example 9.2 Creating Nested Relationships in an XML Schema. • Example 9.3 Creating Tables with Relationships in an XML Schema. • Example 9.4 Transforming XML using XSLT. Bina Nusantara University 13 9.3 Using ADO.NET with XML • ADO.NET provides a number of useful classes and methods to work directly with XML documents. – Data are already in XML form. • This section provides a number of examples that demonstrate XML capabilities of the ADO.NET framework. Bina Nusantara University 14 9.3 Using ADO.NET with XML (cont.) • Complete the following examples listed below in your textbook: – Example 9.5 Processing an XML Document. – Example 9.6 Converting Relational DB Data into XML. – Example 9.7 Using XML and XSLT to Transform Data from a Relational Database. Bina Nusantara University 15