SQL>
SQL> --register schema
SQL> begin
2 dbms_xmlschema.deleteSchema('http://www.example.com/schemas/ipo.xsd',4);
3 end;
4 /
PL/SQL procedure successfully completed.
SQL> begin
2 dbms_xmlschema.registerSchema('http://www.example.com/schemas/ipo.xsd',
3 '
6
7
8 International Purchase order schema for Example.com
9 Copyright 2000 Example.com. All rights reserved.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 ',
61 TRUE, TRUE, FALSE);
62 end;
63 /
PL/SQL procedure successfully completed.
SQL>
SQL> -- create table to hold XML instance documents
SQL> DROP TABLE po_tab;
Table dropped.
SQL> CREATE TABLE po_tab (id number, xmlcol xmltype)
2 XMLTYPE COLUMN xmlcol
3 XMLSCHEMA "http://www.example.com/schemas/ipo.xsd"
4 ELEMENT "purchaseOrder";
Table created.
SQL>
SQL> desc po_tab
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NUMBER
XMLCOL SYS.XMLTYPE(XMLSchema "http:
//www.example.com/schemas/ip
o.xsd" Element "purchaseOrde
r") STORAGE Object-relationa
l TYPE "PurchaseOrderType82_
T"
SQL>
SQL> INSERT INTO po_tab VALUES(1, xmltype(
2 '
3
9
10 Helen Zoe
11 121 Broadway
12 Cardiff
13 Wales
14 UK
15 CF2 1QJ
16
17
18 Robert Smith
19 8 Oak Avenue
20 Old Town
21 CA
22 US
23 95819
24
25
26 -
27 Lapis necklace
28 1
29 99.95
30 Want this for the holidays!
31 1999-12-05
32
33
34 '));
1 row created.
SQL> declare
2 xmldoc xmltype;
3 begin
4 select xmlcol into xmldoc from po_tab p;
5 -- select value(p) into xmldoc from po_tab p;
6 -- validate against XML schema
7 xmldoc.schemavalidate();
8
9 if xmldoc.isschemavalidated() = 1 then
10 dbms_output.put_line('Data is valid');
11 else
12 dbms_output.put_line('Data is invalid');
13 end if;
14 end;
15 /
Data is valid
PL/SQL procedure successfully completed.
SQL> spool off