René Nyffenegger's collection of things on the web | |
René Nyffenegger on Oracle - Most wanted - Feedback
- Follow @renenyffenegger
|
Using schemas with XML DB | ||
Annotating Schemas for XML DB
Schemas can/must be annotated for the use in XML DB. These annotations control how XML documents are stored in the database.
The attributes for the annotations are in a different namespace than the Schema attributes.
The most used annotations are
Local and global Schemas
A Schema can either be registered globally or locally. If it is registered locally, it is only visible to the user who registered it, otherwise, it
is visible to all database users.
An examplebegin dbms_xmlschema.registerSchema ( 'some_dummy_url', ' <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:complexType name="T_person"> <xsd:all> <xsd:element name="first_name" type="xsd:string" /> <xsd:element name="last_name" type="xsd:string" /> <xsd:element name="birth_day" type="xsd:date" /> </xsd:all> <xsd:attribute name="employee_id" type="xsd:positiveInteger" /> </xsd:complexType> <xsd:element name="person" type="T_person" /> </xsd:schema> ', true, -- local true, -- schema compiler will generate object types false, -- don't generate java beans false -- don't allow invalid schemas ); end; / create table xml_person of xmltype xmlschema "some_dummy_url" -- Note: these are double quotes, not single quotes! element "person"; insert into xml_person values ( xmltype (' <person employee_id="3094" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <birth_day>1968-05-31</birth_day> <first_name>Mark</first_name> <last_name>Denver</last_name> </person> ','some_dummy_url') ); |