| Oracle® XML DB Developer's Guide 10g Release 1 (10.1) Part Number B10790-01 |
|
|
View PDF |
This appendix includes the definition and structure of RESOURCE_VIEW and PATH_VIEW and the Oracle XML DB-supplied XML schemas. It also includes a full listing of the C example for loading XML content into Oracle XML DB.
This appendix contains these topics:
The following describes the RESOURCE_VIEW and PATH_VIEW structures.
The RESOURCE_VIEW contains one row for each resource in the repository. The following describes its structure:
Column Datatype Description
------ -------- -------------------------------------------------------
RES XMLType A resource in Oracle XML repository
ANY_PATH VARCHAR2 A path that can be used to access the resource in the
repository
RESID RAW Resource OID which is a unique handle to the resource
The PATH_VIEW contains one row for each unique path in the repository. The following describes its structure:
Column Datatype Description ------ -------- ----------------------------- PATH VARCHAR2 Path name of a resource RES XMLType The resource referred by PATH LINK XMLType Link property RESID RAW Resource OID
Here is the listing for the Oracle XML DB supplied XML schema, XDBResource.xsd, used to represent Oracle XML DB resources.
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://xmlns.oracle.com/xdb/XDBResource.xsd"
version="1.0" elementFormDefault="qualified"
xmlns:res="http://xmlns.oracle.com/xdb/XDBResource.xsd">
<simpleType name="OracleUserName">
<restriction base="string">
<minLength value="1" fixed="false"/>
<maxLength value="4000" fixed="false"/>
</restriction>
</simpleType>
<simpleType name="ResMetaStr">
<restriction base="string">
<minLength value="1" fixed="false"/>
<maxLength value="128" fixed="false"/>
</restriction>
</simpleType>
<simpleType name="SchElemType">
<restriction base="string">
<minLength value="1" fixed="false"/>
<maxLength value="4000" fixed="false"/>
</restriction>
</simpleType>
<simpleType name="GUID">
<restriction base="hexBinary">
<minLength value="8" fixed="false"/>
<maxLength value="32" fixed="false"/>
</restriction>
</simpleType>
<simpleType name="LocksRaw">
<restriction base="hexBinary">
<minLength value="0" fixed="false"/>
<maxLength value="2000" fixed="false"/>
</restriction>
</simpleType>
<simpleType name="LockScopeType">
<restriction base="string">
<enumeration value="Exclusive" fixed="false"/>
<enumeration value="Shared" fixed="false"/>
</restriction>
</simpleType>
<complexType name="LockType" mixed="false">
<sequence>
<element name="owner" type="string"/>
<element name="expires" type="dateTime"/>
<element name="lockToken" type="hexBinary"/>
</sequence>
<attribute name="LockScope" type="res:LockScopeType" />
</complexType>
<complexType name="ResContentsType" mixed="false">
<sequence >
<any name="ContentsAny" />
</sequence>
</complexType>
<complexType name="ResAclType" mixed="false">
<sequence >
<any name="ACLAny"/>
</sequence>
</complexType>
<complexType name="ResourceType" mixed="false">
<sequence >
<element name="CreationDate" type="dateTime"/>
<element name="ModificationDate" type="dateTime"/>
<element name="Author" type="res:ResMetaStr"/>
<element name="DisplayName" type="res:ResMetaStr"/>
<element name="Comment" type="res:ResMetaStr"/>
<element name="Language" type="res:ResMetaStr"/>
<element name="CharacterSet" type="res:ResMetaStr"/>
<element name="ContentType" type="res:ResMetaStr"/>
<element name="RefCount" type="nonNegativeInteger"/>
<element name="Lock" type="res:LocksRaw"/>
<element pname="ACL" type="res:ResAclType" minOccurs="0" maxOccurs="1"/>
<element name="Owner" type="res:OracleUserName" minOccurs="0"
maxOccurs="1"/>
<element name="Creator" type="res:OracleUserName" minOccurs="0"
maxOccurs="1"/>
<element name="LastModifier" type="res:OracleUserName" minOccurs="0"
maxOccurs="1"/>
<element name="SchemaElement" type="res:SchElemType" minOccurs="0"
maxOccurs="1"/>
<element name="Contents" type="res:ResContentsType" minOccurs="0"
maxOccurs="1"/>
<element name="VCRUID" type="res:GUID"/>
<element name="Parents" type="hexBinary" minOccurs="0" maxOccurs="1000"/>
<any name="ResExtra" namespace="##other" minOccurs="0" maxOccurs="65535"/>
</sequence>
<attribute name="Hidden" type="boolean"/>
<attribute name="Invalid" type="boolean"/>
<attribute name="VersionID" type="integer"/>
<attribute name="ActivityID" type="integer"/>
<attribute name="Container" type="boolean"/>
<attribute name="CustomRslv" type="boolean"/>
<attribute name="StickyRef" type="boolean"/>
</complexType>
<element name="Resource" type="res:ResourceType"/>
</schema>
This section describes the Oracle XML DB supplied XML schema used to represent Oracle XML DB access control lists (ACLs):
XML schema, acl.xsd,represents Oracle XML DB access control lists (ACLs):
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://xmlns.oracle.com/xdb/acl.xsd" version="1.0"
xmlns:xdb="http://xmlns.oracle.com/xdb"
xmlns:xdbacl="http://xmlns.oracle.com/xdb/acl.xsd"
elementFormDefault="qualified">
<annotation>
<documentation>
This XML schema describes the structure of XML DB ACL documents.
Note : The following "systemPrivileges" element lists all supported
system privileges and their aggregations.
See dav.xsd for description of DAV privileges
Note : The elements and attributes marked "hidden" are for
internal use only.
</documentation>
<appinfo>
<xdb:systemPrivileges>
<xdbacl:all>
<xdbacl:read-properties/>
<xdbacl:read-contents/>
<xdbacl:read-acl/>
<xdbacl:update/>
<xdbacl:link/>
<xdbacl:unlink/>
<xdbacl:unlink-from/>
<xdbacl:write-acl-ref/>
<xdbacl:update-acl/>
<xdbacl:link-to/>
<xdbacl:resolve/>
</xdbacl:all>
</xdb:systemPrivileges>
</appinfo>
</annotation>
<!-- privilegeNameType (this is an emptycontent type) -->
<complexType name = "privilegeNameType"/>
<!-- privilegeName element
All system and user privileges are in the substitutionGroup
of this element.
-->
<element name = "privilegeName" type="xdbacl:privilegeNameType"
xdb:defaultTable=""/>
<!-- all system privileges in the XML DB ACL namespace -->
<element name = "read-properties" type="xdbacl:privilegeNameType"
substitutionGroup="xdbacl:privilegeName" xdb:defaultTable=""/>
<element name = "read-contents" type="xdbacl:privilegeNameType"
substitutionGroup="xdbacl:privilegeName" xdb:defaultTable=""/>
<element name = "read-acl" type="xdbacl:privilegeNameType"
substitutionGroup="xdbacl:privilegeName" xdb:defaultTable=""/>
<element name = "update" type="xdbacl:privilegeNameType"
substitutionGroup="xdbacl:privilegeName" xdb:defaultTable=""/>
<element name = "link" type="xdbacl:privilegeNameType"
substitutionGroup="xdbacl:privilegeName" xdb:defaultTable=""/>
<element name = "unlink" type="xdbacl:privilegeNameType"
substitutionGroup="xdbacl:privilegeName" xdb:defaultTable=""/>
<element name = "unlink-from" type="xdbacl:privilegeNameType"
substitutionGroup="xdbacl:privilegeName" xdb:defaultTable=""/>
<element name = "write-acl-ref" type="xdbacl:privilegeNameType"
substitutionGroup="xdbacl:privilegeName" xdb:defaultTable=""/>
<element name = "update-acl" type="xdbacl:privilegeNameType"
substitutionGroup="xdbacl:privilegeName" xdb:defaultTable=""/>
<element name = "link-to" type="xdbacl:privilegeNameType"
substitutionGroup="xdbacl:privilegeName" xdb:defaultTable=""/>
<element name = "resolve" type="xdbacl:privilegeNameType"
substitutionGroup="xdbacl:privilegeName" xdb:defaultTable=""/>
<element name = "all" type="xdbacl:privilegeNameType"
substitutionGroup="xdbacl:privilegeName" xdb:defaultTable=""/>
<!-- privilege element -->
<element name = "privilege" xdb:SQLType = "XDB$PRIV_T" xdb:defaultTable="">
<complexType>
<choice maxOccurs="unbounded">
<any xdb:transient="generated"/>
<!-- HIDDEN ELEMENTS -->
<element name = "privNum" type = "hexBinary" xdb:baseProp="true"
xdb:hidden="true"/>
</choice>
</complexType>
</element>
<!-- ace element -->
<element name = "ace" xdb:SQLType = "XDB$ACE_T" xdb:defaultTable="">
<complexType> <sequence>
<element name = "grant" type = "boolean"/>
<element name = "principal" type = "string"
xdb:transient="generated"/>
<element ref="xdbacl:privilege" minOccurs="1"/>
<!-- HIDDEN ELEMENTS -->
<element name = "principalID" type = "hexBinary" minOccurs="0"
xdb:baseProp="true" xdb:hidden="true"/>
<element name = "flags" type = "unsignedInt" minOccurs="0"
xdb:baseProp="true" xdb:hidden="true"/>
</sequence> </complexType>
</element>
<!-- acl element -->
<element name = "acl" xdb:SQLType = "XDB$ACL_T" xdb:defaultTable = "XDB$ACL">
<complexType>
<sequence>
<element name = "schemaURL" type = "string" minOccurs="0"
xdb:transient="generated"/>
<element name = "elementName" type = "string" minOccurs="0"
xdb:transient="generated"/>
<element ref = "xdbacl:ace" minOccurs="1" maxOccurs = "unbounded"
xdb:SQLCollType="XDB$ACE_LIST_T"/>
<!-- HIDDEN ELEMENTS -->
<element name = "schemaOID" type = "hexBinary" minOccurs="0"
xdb:baseProp="true" xdb:hidden="true"/>
<element name = "elementNum" type = "unsignedInt" minOccurs="0"
xdb:baseProp="true" xdb:hidden="true"/>
</sequence>
<attribute name = "shared" type = "boolean" default="true"/>
<attribute name = "description" type = "string"/>
</complexType>
</element>
</schema>';
xdbconfig.xsd, is the Oracle XML DB supplied XML schema used to configure Oracle XML DB:
<schema targetNamespace="http://xmlns.oracle.com/xdb/xdbconfig.xsd"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:xdbc="http://xmlns.oracle.com/xdb/xdbconfig.xsd"
xmlns:xdb="http://xmlns.oracle.com/xdb"
version="1.0" elementFormDefault="qualified">
<element name="xdbconfig" xdb:defaultTable="XDB$CONFIG">
<complexType><sequence>
<!-- predefined XML DB properties - these should NOT be changed -->
<element name="sysconfig">
<complexType><sequence>
<!-- generic XML DB properties -->
<element name="acl-max-age" type="unsignedInt" default="1000"/>
<element name="acl-cache-size" type="unsignedInt" default="32"/>
<element name="invalid-pathname-chars" type="string" default=""/>
<element name="case-sensitive" type="boolean" default="true"/>
<element name="call-timeout" type="unsignedInt" default="300"/>
<element name="max-link-queue" type="unsignedInt" default="65536"/>
<element name="max-session-use" type="unsignedInt" default="100"/>
<element name="persistent-sessions" type="boolean" default="false"/>
<element name="default-lock-timeout" type="unsignedInt"
default="3600"/>
<element name="xdbcore-logfile-path" type="string"
default="/sys/log/xdblog.xml"/>
<element name="xdbcore-log-level" type="unsignedInt" default="0"/>
<element name="resource-view-cache-size" type="unsignedInt"
default="1048576"/>
<element name="case-sensitive-index-clause" type="string" minOccurs="0"/>
<!-- protocol specific properties -->
<element name="protocolconfig">
<complexType><sequence>
<!-- these apply to all protocols -->
<element name="common">
<complexType><sequence>
<element name="extension-mappings">
<complexType><sequence>
<element name="mime-mappings" type="xdbc:mime-mapping-type"/>
<element name="lang-mappings" type="xdbc:lang-mapping-type"/>
<element name="charset-mappings"
type="xdbc:charset-mapping-type"/>
<element name="encoding-mappings"
type="xdbc:encoding-mapping-type"/>
</sequence></complexType>
</element>
<element name="session-pool-size" type="unsignedInt"
default="50"/>
<element name="session-timeout" type="unsignedInt"
default="6000"/>
</sequence></complexType>
</element>
<!-- FTP specific -->
<element name="ftpconfig">
<complexType><sequence>
<element name="ftp-port" type="unsignedShort" default="2100"/>
<element name="ftp-listener" type="string"/>
<element name="ftp-protocol" type="string"/>
<element name="logfile-path" type="string"
default="/sys/log/ftplog.xml"/>
<element name="log-level" type="unsignedInt" default="0"/>
<element name="session-timeout" type="unsignedInt"
default="6000"/>
<element name="buffer-size" default="8192">
<simpleType>
<restriction base="unsignedInt">
<minInclusive value="1024"/> <!-- 1KB -->
<maxInclusive value="1048496"/> <!-- 1MB -->
</restriction>
</simpleType>
</element>
</sequence></complexType>
</element>
<!-- HTTP specific -->
<element name="httpconfig">
<complexType><sequence>
<element name="http-port" type="unsignedShort" default="8080"/>
<element name="http-listener" type="string"/>
<element name="http-protocol" type="string"/>
<element name="max-http-headers" type="unsignedInt"
default="64"/>
<element name="max-header-size" type="unsignedInt"
default="4096"/>
<element name="max-request-body" type="unsignedInt"
default="2000000000" minOccurs="1"/>
<element name="session-timeout" type="unsignedInt"
default="6000"/>
<element name="server-name" type="string"/>
<element name="logfile-path" type="string"
default="/sys/log/httplog.xml"/>
<element name="log-level" type="unsignedInt" default="0"/>
<element name="servlet-realm" type="string" minOccurs="0"/>
<element name="webappconfig">
<complexType><sequence>
<element name="welcome-file-list"
type="xdbc:welcome-file-type"/>
<element name="error-pages" type="xdbc:error-page-type"/>
<element name="servletconfig"
type="xdbc:servlet-config-type"/>
</sequence></complexType>
</element>
<element name="default-url-charset" type="string"
minOccurs="0"/>
</sequence></complexType>
</element>
</sequence></complexType>
</element>
</sequence></complexType>
</element>
<!-- users can add any properties they want here -->
<element name="userconfig" minOccurs="0">
<complexType><sequence>
<any maxOccurs="unbounded" namespace="##other"/>
</sequence></complexType>
</element>
</sequence></complexType>
</element>
<complexType name="welcome-file-type">
<sequence>
<element name="welcome-file" minOccurs="0" maxOccurs="unbounded">
<simpleType>
<restriction base="string">
<pattern value="[^/]*"/>
</restriction>
</simpleType>
</element>
</sequence>
</complexType>
<!-- customized error pages -->
<complexType name="error-page-type">
<sequence>
<element name="error-page" minOccurs="0" maxOccurs="unbounded">
<complexType><sequence>
<choice>
<element name="error-code">
<simpleType>
<restriction base="positiveInteger">
<minInclusive value="100"/>
<maxInclusive value="999"/>
</restriction>
</simpleType>
</element>
<!-- Fully qualified classname of a Java exception type -->
<element name="exception-type" type="string"/>
<element name="OracleError">
<complexType><sequence>
<element name="facility" type="string" default="ORA"/>
<element name="errnum" type="unsignedInt"/>
</sequence></complexType>
</element>
</choice>
<element name="location" type="anyURI"/>
</sequence></complexType>
</element>
</sequence>
</complexType>
<!-- parameter for a servlet: name, value pair and a description -->
<complexType name="param">
<sequence>
<element name="param-name" type="string"/>
<element name="param-value" type="string"/>
<element name="description" type="string"/>
</sequence>
</complexType>
<complexType name="servlet-config-type">
<sequence>
<element name="servlet-mappings">
<complexType><sequence>
<element name="servlet-mapping" minOccurs="0"
maxOccurs="unbounded">
<complexType><sequence>
<element name="servlet-pattern" type="string"/>
<element name="servlet-name" type="string"/>
</sequence></complexType>
</element>
</sequence></complexType>
</element>
<element name="servlet-list">
<complexType><sequence>
<element name="servlet" minOccurs="0" maxOccurs="unbounded">
<complexType><sequence>
<element name="servlet-name" type="string"/>
<element name="servlet-language">
<simpleType>
<restriction base="string">
<enumeration value="C"/>
<enumeration value="Java"/>
<enumeration value="PL/SQL"/>
</restriction>
</simpleType>
</element>
<element name="icon" type="string" minOccurs="0"/>
<element name="display-name" type="string"/>
<element name="description" type="string" minOccurs="0"/>
<choice>
<element name="servlet-class" type="string" minOccurs="0"/>
<element name="jsp-file" type="string" minOccurs="0"/>
</choice>
<element name="servlet-schema" type="string" minOccurs="0"/>
<element name="init-param" minOccurs="0"
maxOccurs="unbounded" type="xdbc:param"/>
<element name="load-on-startup" type="string" minOccurs="0"/>
<element name="security-role-ref" minOccurs="0"
maxOccurs="unbounded">
<complexType><sequence>
<element name="description" type="string" minOccurs="0"/>
<element name="role-name" type="string"/>
<element name="role-link" type="string"/>
</sequence></complexType>
</element>
</sequence></complexType>
</element>
</sequence></complexType>
</element>
</sequence>
</complexType>
<complexType name="lang-mapping-type"><sequence>
<element name="lang-mapping" minOccurs="0" maxOccurs="unbounded">
<complexType><sequence>
<element name="extension" type="xdbc:exttype"/>
<element name="lang" type="string"/>
</sequence></complexType>
</element></sequence>
</complexType>
<complexType name="charset-mapping-type"><sequence>
<element name="charset-mapping" minOccurs="0" maxOccurs="unbounded">
<complexType><sequence>
<element name="extension" type="xdbc:exttype"/>
<element name="charset" type="string"/>
</sequence></complexType>
</element></sequence>
</complexType>
<complexType name="encoding-mapping-type"><sequence>
<element name="encoding-mapping" minOccurs="0" maxOccurs="unbounded">
<complexType><sequence>
<element name="extension" type="xdbc:exttype"/>
<element name="encoding" type="string"/>
</sequence></complexType>
</element></sequence>
</complexType>
<complexType name="mime-mapping-type"><sequence>
<element name="mime-mapping" minOccurs="0" maxOccurs="unbounded">
<complexType><sequence>
<element name="extension" type="xdbc:exttype"/>
<element name="mime-type" type="string"/>
</sequence></complexType>
</element></sequence>
</complexType>
<simpleType name="exttype">
<restriction base="string">
<pattern value="[^\*\./]*"/>
</restriction>
</simpleType>
</schema>
The following example is also partially listed in Chapter 3, " Using Oracle XML DB", "Loading XML Content into Oracle XML DB Using C":
Example H-1 Loading XML Content into Oracle XML DB Using C
#include <xml.h>
#include <string.h>
#include <ocixmldb.h>
OCIEnv *envhp;
OCIError *errhp;
OCISvcCtx *svchp;
OCIStmt *stmthp;
OCIServer *srvhp;
OCIDuration dur;
OCISession *sesshp;
oratext *username;
oratext *password;
oratext *filename;
oratext *schemaloc;
/*--------------------------------------------------------*/
/* execute a sql statement which binds xml data */
/*--------------------------------------------------------*/
sword exec_bind_xml(OCISvcCtx *svchp, OCIError *errhp, OCIStmt *stmthp,
void *xml, OCIType *xmltdo, OraText *sqlstmt){
OCIBind *bndhp1 = (OCIBind *) 0;
sword status = 0;
OCIInd ind = OCI_IND_NOTNULL;
OCIInd *indp = &ind;
if(status = OCIStmtPrepare(stmthp, errhp, (OraText *)sqlstmt,
(ub4)strlen((const char *)sqlstmt),
(ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT))
return OCI_ERROR;
if(status = OCIBindByPos(stmthp, &bndhp1, errhp, (ub4) 1, (dvoid *) 0,
(sb4) 0, SQLT_NTY, (dvoid *) 0, (ub2 *)0,
(ub2 *)0, (ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT))
return OCI_ERROR;
if(status = OCIBindObject(bndhp1, errhp, (CONST OCIType *) xmltdo,
(dvoid **) &xml, (ub4 *) 0,
(dvoid **) &indp, (ub4 *) 0))
return OCI_ERROR;
if(status = OCIStmtExecute(svchp, stmthp, errhp, (ub4) 1, (ub4) 0,
(CONST OCISnapshot*) 0, (OCISnapshot*) 0,
(ub4) OCI_DEFAULT))
return OCI_ERROR;
return OCI_SUCCESS;}
/*--------------------------------------------------------*/
/* initialize oci handles and connect */
/*--------------------------------------------------------*/
sword init_oci_connect(){
sword status;
if (OCIEnvCreate((OCIEnv **) &(envhp), (ub4) OCI_OBJECT,
(dvoid *) 0, (dvoid * (*)(dvoid *,size_t)) 0,
(dvoid * (*)(dvoid *, dvoid *, size_t)) 0,
(void (*)(dvoid *, dvoid *)) 0, (size_t) 0, (dvoid **) 0))
{
printf("FAILED: OCIEnvCreate()\n");
return OCI_ERROR;
}
/* allocate error handle */
if (OCIHandleAlloc((dvoid *) envhp, (dvoid **) &(errhp),
(ub4) OCI_HTYPE_ERROR, (size_t) 0, (dvoid **) 0))
{
printf("FAILED: OCIHandleAlloc() on errhp\n");
return OCI_ERROR;
}
/* allocate server handle */
if (status = OCIHandleAlloc((dvoid *) envhp, (dvoid **) &srvhp,
(ub4) OCI_HTYPE_SERVER, (size_t) 0, (dvoid **) 0))
{
printf("FAILED: OCIHandleAlloc() on srvhp\n");
return OCI_ERROR;
}
/* allocate service context handle */
if (status = OCIHandleAlloc((dvoid *) envhp,
(dvoid **) &(svchp), (ub4) OCI_HTYPE_SVCCTX,
(size_t) 0, (dvoid **) 0))
{
printf("FAILED: OCIHandleAlloc() on svchp\n");
return OCI_ERROR;
}
/* allocate session handle */
if (status = OCIHandleAlloc((dvoid *) envhp, (dvoid **) &sesshp ,
(ub4) OCI_HTYPE_SESSION, (size_t) 0, (dvoid **) 0))
{
printf("FAILED: OCIHandleAlloc() on sesshp\n");
return OCI_ERROR;
}
/* allocate statement handle */
if (OCIHandleAlloc((dvoid *)envhp, (dvoid **) &stmthp,
(ub4)OCI_HTYPE_STMT, (CONST size_t) 0, (dvoid **) 0))
{
printf("FAILED: OCIHandleAlloc() on stmthp\n");
return status;
}
if (status = OCIServerAttach((OCIServer *) srvhp, (OCIError *) errhp,
(CONST oratext *)"", 0, (ub4) OCI_DEFAULT))
{
printf("FAILED: OCIServerAttach() on srvhp\n");
return OCI_ERROR;
}
/* set server attribute to service context */
if (status = OCIAttrSet((dvoid *) svchp, (ub4) OCI_HTYPE_SVCCTX,
(dvoid *) srvhp, (ub4) 0, (ub4) OCI_ATTR_SERVER,
(OCIError *) errhp))
{
printf("FAILED: OCIAttrSet() on svchp\n");
return OCI_ERROR;
}
/* set user attribute to session */
if (status = OCIAttrSet((dvoid *)sesshp, (ub4) OCI_HTYPE_SESSION,
(dvoid *)username,
(ub4) strlen((const char *)username),
(ub4) OCI_ATTR_USERNAME, (OCIError *) errhp))
{
printf("FAILED: OCIAttrSet() on authp for user\n");
return OCI_ERROR;
}
/* set password attribute to session */
if (status = OCIAttrSet((dvoid *) sesshp, (ub4) OCI_HTYPE_SESSION,
(dvoid *)password,
(ub4) strlen((const char *)password),
(ub4) OCI_ATTR_PASSWORD, (OCIError *) errhp))
{
printf("FAILED: OCIAttrSet() on authp for password\n");
return OCI_ERROR;
}
/* Begin a session */
if (status = OCISessionBegin((OCISvcCtx *) svchp,
(OCIError *) errhp,
(OCISession *) sesshp, (ub4) OCI_CRED_RDBMS,
(ub4) OCI_STMT_CACHE))
{
printf("FAILED: OCISessionBegin(). Make sure database is up and
the username/password is valid. \n");
return OCI_ERROR;
}
/* set session attribute to service context */
if (status = OCIAttrSet((dvoid *) svchp, (ub4) OCI_HTYPE_SVCCTX,
(dvoid *)sesshp, (ub4) 0, (ub4) OCI_ATTR_SESSION,
(OCIError *) errhp))
{
printf("FAILED: OCIAttrSet() on svchp\n");
return OCI_ERROR;
}}
/*--------------------------------------------------------*/
/* free oci handles and disconnect */
/*--------------------------------------------------------*/
void free_oci(){
sword status = 0;
/* End the session */
if (status = OCISessionEnd((OCISvcCtx *)svchp, (OCIError *)errhp,
(OCISession *)sesshp, (ub4) OCI_DEFAULT))
{
if (envhp)
OCIHandleFree((dvoid *)envhp, OCI_HTYPE_ENV);
return;
}
/* Detach from the server */
if (status = OCIServerDetach((OCIServer *)srvhp, (OCIError *)errhp,
(ub4)OCI_DEFAULT))
{
if (envhp)
OCIHandleFree((dvoid *)envhp, OCI_HTYPE_ENV);
return;
}
/* Free the handles */
if (stmthp)
OCIHandleFree((dvoid *)stmthp, (ub4) OCI_HTYPE_STMT);
if (sesshp)
OCIHandleFree((dvoid *)sesshp, (ub4) OCI_HTYPE_SESSION);
if (svchp)
OCIHandleFree((dvoid *)svchp, (ub4) OCI_HTYPE_SVCCTX);
if (srvhp)
OCIHandleFree((dvoid *)srvhp, (ub4) OCI_HTYPE_SERVER);
if (errhp)
OCIHandleFree((dvoid *)errhp, (ub4) OCI_HTYPE_ERROR);
if (envhp)
OCIHandleFree((dvoid *)envhp, (ub4) OCI_HTYPE_ENV);
return;}
void main(){
OCIType *xmltdo;
xmldocnode *doc;
ocixmldbparam params[1];
xmlerr err;
xmlctx *xctx;
oratext *ins_stmt;
sword status;
/* Initialize envhp, svchp, errhp, dur, stmthp */
init_oci_connect();
/* Get an xml context */
params[0].name_ocixmldbparam = XCTXINIT_OCIDUR;
params[0].value_ocixmldbparam = &dur;
xctx = OCIXmlDbInitXmlCtx(envhp, svchp, errhp, params, 1);
if (!(doc = XmlLoadDom(xctx, &err, "file", filename,
"schema_location", schemaloc, NULL)))
{
printf("Parse failed.\n");
return;
}
else
printf("Parse succeeded.\n");
printf("The xml document is :\n");
XmlSaveDom(xctx, &err, (xmlnode *)doc, "stdio", stdout, NULL);
/* Insert the document to my_table */
ins_stmt = (oratext *)"insert into PURCHASEORDER values (:1)";
status = OCITypeByName(envhp, errhp, svchp, (const text *) "SYS",
(ub4) strlen((const char *)"SYS"), (const text *) "XMLTYPE",
(ub4) strlen((const char *)"XMLTYPE"), (CONST text *) 0,
(ub4) 0, OCI_DURATION_SESSION, OCI_TYPEGET_HEADER,
(OCIType **) &xmltdo);
if (status == OCI_SUCCESS)
{
status = exec_bind_xml(svchp, errhp, stmthp, (void *)doc,
xmltdo, ins_stmt);
}
if (status == OCI_SUCCESS)
printf ("Insert successful\n");
else
printf ("Insert failed\n");
/* free xml instances */
if (doc)
XmlFreeDocument((xmlctx *)xctx, (xmldocnode *)doc);
/* free xml ctx */
OCIXmlDbFreeXmlCtx(xctx);
free_oci();}