Running the Java Stored Procedure
After you have successfully created the Java stored procedure, you can test it by creating a table that stores the XML Schema documents and loading the sample data in SQL*Plus as follows:CREATE TABLE xsd_tbl(
name VARCHAR2(30) PRIMARY KEY,
doc VARCHAR2(4000));
INSERT INTO xsd_tbl VALUES('Product.xsd','<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xsd:complexType name="ProductType">
<xsd:sequence>
<xsd:element name="Type" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>');
commit;
You then can call the xsd_build() Java stored procedure to parse the XML schema document stored in the xsd_tbl table by using the following PL/SQL code:
SET AUTOPRINT ON
VAR out VARCHAR2(2000)
DECLARE
xsd VARCHAR2(4000);
BEGIN
SELECT doc INTO xsd FROM xsd_tbl WHERE name='Product.xsd';
:out := xsd_build(xsd);
END;
If there are no errors in the XML Schema document, you will receive a message stating The Input XSD Parsed Without Errors. Otherwise, any error messages will be printed on the screen because all messages printed to a StringWriter in a Java program are returned and printed using the DBMS_OUTPUT package.