270 likes | 409 Views
Oracle XML Developer’s Kit – XDK Spring 2002. An Example of XML. <?xml version="1.0" ?> <!DOCTYPE transaction (View Source for full doctype...) > - <transaction> <account> 89-344 </account> - <buy shares=" 100 "> <ticker exch=" NASDAQ "> WEBM </ticker> </buy>
E N D
An Example of XML • <?xml version="1.0" ?> • <!DOCTYPE transaction (View Source for full doctype...)> • - <transaction> • <account>89-344</account> • - <buy shares="100"> • <ticker exch="NASDAQ">WEBM</ticker> • </buy> • - <sell shares="30"> • <ticker exch="NYSE">GE</ticker> • </sell> • </transaction>
Oracle XDK Definition Is Oracle’s collection of XML-based tools for reading, manipulating, transforming, and viewing XML documents.
XDK for C XDK for PL/SQL XDK for C++ XDK for Java XDK Language Support
XML Parser for Java XML Schema Processor for Java XML Class Generator for Java XSQL Servlet XDK Components & Utilities
XML Parsing Definition The process of converting the unstructured sequence of characters representing an XML document into the structured components such as XML syntax, declaration, comments, elements, attributes, processing instructions, and characters.
Markup Definition • An encoded description of a document’s storage layout and logical structure.
XML parser for Java Java supports two XML parser APIs • SAX parser API (Event based Simple API) • DOM parser API (Tree based Document Object Model)
SAX API (Event Based) • SAX API uses calls to report parsing events to the application. • Events include the start and end of elements or characters. e.g. <transaction> . . .</transaction> <countNum>8923</countNum>
DOM API (Tree Based) • DOM API builds an in-memory tree representation of the XML document. It provides classes and methods for an application to navigate and process the tree.
XML Parser for Java using SAX API Import org.xml.sax.*; Import oracle.xml.parser.v2. *; public static void main(String[], argv) { try { // Get an instance of the parser Parser parser = new SAXParser(); // Create a SAX event handler and register it with the parser SAXHandler handler = new SAXHandler(); parse.setDocumentHandler(handler); // Convert file to InputSource and parse InputSource xmldoc = new InputSource(new FileInputStream(argv[0])); parser.parse(xmldoc); } catch (Exception e) {…} }
Xml Parser for Java using DOM API • Import java.xml.parser.v2.DOMparser; • Import org.w3c.dom.*; • Import org.w3c.dom.Node; • Import oracle.xml.parser.v2.XMLElement; • Import oracle. Xml.parser.v2.XMLAttr; … // generate a new input stream from given file FileInputStream xmldoc = new FileInputStream(avgv[0]); // parse the document using domparser DOMParser parser = new DOMParser(); parser.parse(xmldoc); // obtain the document. Document doc = parser.getDocument(); // print some information regarding attributes of elements in the document printElementAtrributes(doc); …
SAX is useful for applications that do not need to manipulate the XML tree, such as search operations, among others. DOM is most useful for structural manipulations of the XML tree, such as reordering elements, adding or deleting elements and attributes, renaming elements, and so 0n. SAX Versus DOM
DOM API & SAX API • DOM API is more powerful; however, it is memory intensive. • SAX API is fast, less memory is needed, and it works for extreme large document.
To run the parsing programs: • Add xmlparserv2.jar and the current directory to the CLASSPATH. • Run the program for DOM/SAX APIs as follows: • java <classname> <sample xml file>
XML Schema for Java • XML Schema is being drawn up by W3C to describe the content and structure of XML documents in XML. It includes the full capabilities of DTDs so that existing DTDs can be converted to XML Schema. XML Schemas have additional capabilities over DTDs.
How to Run XML Schema for Java • Add xmlparserv2.jar, xschema.jar, and the current directory to the CLASSPATH. • E.g. to run the program with the report.xml file, the command line is: • java XSDSample report.xml
XML Class Generators for Java • XML provides two Class Generators for Java: • DTD Class Generator • XML Schema Class Generator
XML Class Generator for Java • Creates Java source files based on: • XML DTDs • XML Schema Definition • It can be used when an application wants to send an XML message to another application based on agreed-upon DTDs or XML Schemas.
XSQL Servlet Definition • It is a Java servlet that can run in the Web server to produce dynamic XML documents based on one or more SQL queries. • It combines the power of SQL, XML, and XSLT to publish dynamic web content based on database information
XSQL Pages Usage • It is an XML file that contains specific elements to direct the action of the servlet. • XSQL page is server-side template. It can publish any information in any format to any device
Basic XSQL Features • Producing XML Datagrams from SQL Queries • Transforming the XML Datagram into an Alternative XML Format • Transforming the XML Datagram into HTML for displaying
XSQL Example <!----EmpOver2000.xsql--- > <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="EmpOver2000.xsl"?> <xsql:query connection=“myDemo" xmlns:xsql="urn:oracle-xsql"> SELECT empno, ename, sal, deptno FROM emp where sal > '{@salary}' ORDER BY ename DESC </xsql:query>
XSQL Example (cont.) <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- Import all the templates from "TableBaseWithCSS.xsl" as a base --> <xsl:import href="TableBaseWithCSS.xsl"/> <!-- Override Imported template for ROW to match ROW's with a SAL > 2000 --> <xsl:template match="ROW[ SAL > 2000 ]"> <tr class="Highlight"><xsl:apply-templates/> </tr> </xsl:template> </xsl:stylesheet>