220 likes | 362 Views
XML with RDBMS. coping with the paradigm issue. XML Storage options. Incoming XML can be treated in different ways, depending on what your application needs: Store XML in OS File with a pointer Bring the file,as is, into a table (CLOB)
E N D
XML with RDBMS coping with the paradigm issue
XML Storage options • Incoming XML can be treated in different ways, depending on what your application needs: • Store XML in OS File with a pointer • Bring the file,as is, into a table (CLOB) • Read the file, and programmatically break it up and put into relational storage • Store in a XMLDB repository
http://otn.oracle.com/tech/xml/xmldb/pdf/XMLDB_Technical_Whitepaper.pdfhttp://otn.oracle.com/tech/xml/xmldb/pdf/XMLDB_Technical_Whitepaper.pdf Oracle XML DB White Paper
Tamino • "Storing XML documents in a true native XML data store integrated in an XML server is the key for to keeping pace with steadily increasing business dynamics. And it is the best way to respond to demands for maximum performance and scalability, with the lowest operational and administration costs" http://www1.softwareag.com/Corporate/products/tamino/prod_info/default.asp "Here's why you too should choose XML technology"
Tamino architecture http://www1.softwareag.com/Corporate/products/tamino/prod_info/architecture/default.asp
Generic approach http://www.research.att.com/~sihem/shrex/shrex-widm2004.pdf
Doing XML in Oracle • XML_DB • Getting XML out from Oracle • Getting XML into Oracle • Procedural approach • SQLLDR • Oracle XML Developer's Kit 10g
XML_DB • Oracle XML DB is fully compliant with the W3C XML data model • provides new standard access methods for XML navigation and query. • Not a Separate Database Server • Technical white paper: • http://download-uk.oracle.com/technology/tech/xml/xmldb/current/twp.pdf
XML_DB features • XMLType • is a native datatype • extend CLOB datatype • used to store and manage XML documents • Columns CREATE TABLE NewCDInfo ( DateTime_Recd Date DEFAULT SYSDATE, SourceFileName Varchar2(60), XMLContent XMLType) ; • or Tables CREATE TABLE CDXML of XMLType;
XML_DB features • REGISTERING AN XML SCHEMA • XML Schema registered by calling the PL/SQL procedure: dbms_xmlschema.register_schema() • An XML Schema registration caused a default table to be created for each element in the XML Schema. • When an instance document is loaded in the Oracle XML_DB repository, the content of the document will be stored in the default table. • NOTE: tables created by this process are XMLType tables: • Object tables where each row is represented as an instance of the XMLType datatype
XML_DB benefits • The ability to store and manage both structured and unstructured data under the same standard W3C XML data model (XML Schema). • Complete transparency and interchangeability between the XML and SQL data views. • FTP, and WebDAV protocol support. • Store XML in the database and render it queryable and at the same time access it through popular desktop tools. • Claimed by XML_DB manual: • (http://oracledocs.shu.ac.uk/oracle/10.1/GenericV1/appdev.101/b10790/xdb01int.htm#i1047230)
XML_DB uses include: • Business-to-Business (B2B) and Application-to-Application (A2A) integration • Content-management applications • Web Services • A typical Oracle XML DB application has one or more of the following requirements and characteristics: • Large numbers of XML documents must be ingested or generated • Large XML documents need to be processed or generated • High performance searching, both within a document and across a large collections of documents • High Levels of security. Fine grained control of security • Uses languages such as Java that support open standards such as SQL, XML, XPath, and XSLT • Accesses information using standard Internet protocols such as FTP, HTTP/WebDAV, or JDBC • Full queriability from SQL and integration with analytic capabilities • Validation of XML documents is critical http://oracledocs.shu.ac.uk/oracle/10.1/GenericV1/appdev.101/b10790/xdb02rep.htm#i1034512
XML_DB systems design factors: • Data • Structured? • Schema based? • Access • How do applications get to the data? • security • Application Language • What are your organisations skillsets? • Performance issues http://oracledocs.shu.ac.uk/oracle/10.1/GenericV1/appdev.101/b10790/xdb02rep.htm#i1034512
Getting XML Out using XML SQL Utility (XSU). • XSU Java Servlet released Oracle8i • In Oracle9i+ improved functionality and PL/SQL APIs • Two key packages: • DBMS_XMLQuery • getXML • getDTD • DBMS_XMLSave
Getting XML Out using XML SQL Utility (XSU). • The basic stages of the procedure are: • Assign the Select that generates the data we want to the context called Qry • Use the DBMS_XMLQuery procedure called getXML to return the result set, and put the resultant CLOB into the pre-defined variable Members_xml. • Contexts need to be closed • Return the generated CLOB as a result
From Table to XML CREATE OR REPLACE FUNCTION membernames2xml RETURN CLOB IS members_xml CLOB; Qry DBMS_XMLQuery.ctxType; BEGIN Qry := DBMS_XMLQuery.newContext('SELECT * FROM member'); Members_xml := DBMS_XMLQuery.getXML(Qry); DBMS_XMLQuery.closeContext(Qry); RETURN members_xml ; END; /
Outputing XML with XML_DB SQL extentions set pagesize 0 set long 10000 select '<?xml version="1.0"?>' from dual ; select '<ROWSET>' from dual ; SELECT xmlelement("CD", xmlforest(a.composer, b.title, b.cdid)) FROM composers a, cds b where a.composerid=b.composerid and a.composerid < 10 ; select '</ROWSET>' from dual ;
IVY • To carry out the server-side procedures in the tutorial you need to have access to a folder that the Oracle Server can access • Log in to Ivy using Telnet and run: /usr/local/bin/oracle_dir • This process creates a Database Directory Object which maps to the user's home directory on ivy and the F: drive: /homedir/oracle_work • The Directory object has the following name: • USERNAME_ORACLE_WORK • For example: CMSPL4_ORACLE_WORK
Inserting to a table from XML • We can insert XML directly into a table of type XMLType: • drop table CDXML ; • CREATE TABLE CDXML of XMLType; Declare this_clob CLOB ; Begin this_clob:=getclobfromfile('CMSPL4_ORACLE_WORK','NewCD1471.xml'); INSERT INTO CDXML VALUES ( xmltype ( this_clob ) ); END ; / • set long 1000 • select * from CDXML ;
Inserting to a table from XML • There are more steps involved than there were for generating XML from SQL. We need to: • read the XML file from the OS or URL • PARSE it (make some sense of it) • Put it in a memory structure that we can manipulate it (a DOM document). • Decide how we will handle the mapping to fields • And then insert the data • See example in tutorial