Oracle9i Application Developer's Guide - XML Release 1 (9.0.1) Part Number A88894-01 |
|
This chapter contains the following sections:
The XML Schema Processor for C++ is a companion component to the XML Parser for C++ that allows support to simple and complex datatypes into XML applications with Oracle9i. The Schema Processor supports the XML Schema Working Draft, with the goal being that it be 100% fully conformant when XML Schema becomes a W3C Recommendation. This makes writing custom applications that process XML documents straightforward in the Oracle9i environment, and means that a standards-compliant XML Schema Processor is part of the Oracle9i platform on every operating system where Oracle9i is ported.
See Also:
Chapter 20, "Using XML Parser for Java", for more information about XML Schema and why you would want to use XML Schema. |
XML Schema Processor for C++ has the following features:
The XML Schema Processor for C++ class is XMLSchema
. The version described here is Oracle XML Schema Processor 1.0.1.0.0 (C++). The Oracle XML Schema Processor is an early adopter release and is written in C with a C++ wrapper. It includes the production release of the XML Parser for C v2.
XML Schema Processor for C++ runs on the following operating systems:
Documentation for Oracle XML Schema Processor for C++ is located in the doc directory in your install area.
The parser conforms to the following standards:
The XML Parser for C++ currently supports the following encodings:
Appendix A, Character Sets, of the Oracle9i Globalization and National Language Support Guide, where, in addition, any character set specified in can be used.
See Also:
To use these encodings, you must have the following set:
The default encoding is UTF-8. It is recommended that you set the default encoding explicitly if using only single byte character sets (such as US-ASCII or any of the ISO-8859 character sets) for performance up to twice as fast as with multibyte character sets, such as UTF-8.
Table 27-1 lists the supplied files and directories with this release:
Table 27-2 lists the included libraries:
Included Library | Description |
---|---|
libxml8.a |
XML Parser/XSL Processor |
libcore8.a |
CORE functions |
libnls8.a |
National Language Support |
The XML Schema Processor can be called as an executable by invoking bin/schema in the install area. This takes two arguments:
The Schema processor can also be invoked by writing code using the supplied APIs. The code must be compiled using the headers in the include/ subdirectory and linked against the libraries in the lib/ subdirectory. See Makefile in the sample/ subdirectory for details on how to build your program.
An error message file is provided in the mesg/ subdirectory. Currently, the only message file is in English although message files for other languages may be supplied in future releases.
You should set the environment variable ORA_XML_MESG to point to the "absolute" path of the mesg/ subdirectory. Alternately, if you have an $ORACLE_HOME installed, you may copy the contents of the mesg/ subdirectory to the $ORACLE_HOME/oracore/mesg directory.
Figure 27-1 illustrates the calling sequence of XMl Schema Processor for C++, as follows:
This directory contains a sample XML Schema application that illustrates how to use Oracle XML Schema Processor with its API. Table 27-3 lists the provided sample files.
Sample File | Description |
---|---|
Makefile |
Makefile to build the sample programs and run them, verifying correct output. |
xsdtest.cpp |
Trivial program which invokes the XML Schema for C++ API |
car.{xsd,xml,std} |
Sample Schema, instance document, expected output respectively, after running xsdtest on them. See: "XML Schema for C++ Example 2: car.xsd" |
aq.{xsd,xml,std} |
Second sample Schema's, instance document, expected output respectively, after running xsdtest on them. See: "XML Schema for C++ Example 5: aq.xsd" |
pub.{xsd,xml,std} |
Third sample Schema's, instance document, expected output respectively, after running xsdtest on them. See: "XML Schema for C++ Example 8: pub.xsd" |
To build the sample programs, run 'make'.
To build the programs and run them, comparing the actual output to expected output, run 'make sure'.
An error message file is provided in the mesg subdirectory. Currently, the only message file is in English although message files for other languages may be supplied in future releases. You should set the environment variable ORA_XML_MESG to point to the absolute path of the mesg subdirectory.
Alternately, if you have an $ORACLE_HOME installed, you can copy the contents of the mesg subdirectory to the $ORACLE_HOME/oracore/mesg directory.
// Copyright (c) Oracle Corporation 1999, 2000. All Rights Reserved. /////////////////////////////////////////////////////////////////////////////// // NAME validate.cpp // DESCRIPTION Sample usage of C++ XML Schema processor /////////////////////////////////////////////////////////////////////////////// #include <iostream.h> #include <string.h> #ifndef ORAXML_CPP_ORACLE # include <oraxml.hpp> #endif #ifndef ORAXSD_CPP_ORACLE # include <oraxsd.hpp> #endif int main(int argc, char **argv) { XMLSchema schema; XMLParser parser; xmlctx *ctx; char *doc, *uri; uword ecode; cout << "XML C++ Schema processor\n"; if ((argc < 2) || (argc > 3)) { cout << "usage: validate <xml document> [schema]\n"; return -1; } doc = argv[1]; uri = (argc > 2) ? argv[2] : 0; cout << "Initializing XML package...\n"; if (ecode = parser.xmlinit()) { cout << "Failed to initialize XML parser, error " << ecode; return 1; } cout << "Parsing '" << doc << "'...\n"; if (ecode = parser.xmlparse((oratext *) doc, (oratext *) 0, XML_FLAG_DISCARD_WHITESPACE)) { cout << "Parse failed, error " << ecode << "\n"; return 2; } cout << "Initializing Schema package...\n"; if (ecode = schema.initialize(&parser)) { cout << "Failed, code " << ecode << "!\n"; return 3; } cout << "Validating document...\n"; if (ecode = schema.validate(&parser, (oratext *) uri)) { cout << "Validation failed, error " << ecode << "\n"; return 4; } cout << "Document is valid.\n"; schema.terminate(); return 0; }
<?xml version="1.0"?> <schema xmlns = "http://www.w3.org/1999/XMLSchema" targetNamespace = "http://www.CarDealers.com/"> <element name="Car"> <complexType> <element name="Model"> <simpleType base="string"> <enumeration value = "Ford"/> <enumeration value = "Saab"/> <enumeration value = "Audi"/> </simpleType> </element> <element name="Make"> <simpleType base="string"> <minLength value = "1"/> <maxLength value = "30"/> </simpleType> </element> <element name="Year"> <complexType content="mixed"> <attribute name="PreviouslyOwned" type="string" use="required"/> <attribute name="YearsOwned" type="integer" use="optional"/> </complexType> </element> <element name="OwnerName" type="string" minOccurs="0" maxOccurs="unbounded"/> <element name="Condition"> <complexType base="string" derivedBy="extension"> <attribute name="Automatic"> <simpleType base="string"> <enumeration value = "Yes"/> <enumeration value = "No"/> </simpleType> </attribute> </complexType> </element> <element name="Mileage"> <simpleType base="integer"> <minInclusive value="0"/> <maxInclusive value="2000000"/> </simpleType> </element> <attribute name="RequestDate" type="date"/> </complexType> </element> </schema>
<?xml version="1.0"?> <car:Car xmlns:car="http://www.CarDealers.com/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xsi:schemaLocation="http://www.CarDealers.com/ car.xsd" RequestDate="2000-12-6"> <Model>Ford</Model> <Make>Explorer</Make> <Year PreviouslyOwned="You betcha">1999</Year> <OwnerName>Joe Smith</OwnerName> <OwnerName>Bob Jones</OwnerName> <Condition Automatic="No">Small dent on right bumper.</Condition> <Mileage>1999999</Mileage> </car:Car>
XML C++ Schema processor Initializing XML package... Parsing 'car.xml'... Initializing Schema package... Validating document... Document is valid.
<?xml version="1.0"?> <!-- ****************** AQ xml schema ****************** --> <schema xmlns = "http://www.w3.org/1999/XMLSchema" targetNamespace = "http://www.oracle.com/AQXmlDocument" xmlns:aq = "http://www.oracle.com/AQXmlDocument" xmlns:xsd = "http://www.w3.org/1999/XMLSchema" elementFormDefault="qualified"> <element name="AQXmlDocument"> <complexType content="mixed"> <choice> <group ref="aq:client_operation" minOccurs="0"/> <group ref="aq:server_response"/> </choice> </complexType> </element> <!-- ****************** Client Operations Group ****************** --> <group name="client_operation"> <sequence> <element ref="aq:client_operation" minOccurs="0" maxOccurs="1"/> <choice> <element ref="aq:producer_options" maxOccurs="1"/> <element ref="aq:consumer_options" maxOccurs="1"/> <element ref="aq:register_options" maxOccurs="1"/> </choice> <element ref="aq:message_set" minOccurs="0" maxOccurs="*"/> </sequence> </group> <!-- ****************** Server Response Group ****************** --> <group name="server_response"> <sequence> <element ref="aq:server_response" minOccurs="0" maxOccurs="1"/> <element ref="aq:receive_result" maxOccurs="1"/> <choice minOccurs="0" > <element ref="aq:send_result" maxOccurs="1"/> <element ref="aq:publish_result" maxOccurs="1"/> <element ref="aq:receive_result" maxOccurs="1"/> <element ref="aq:sequence_num_result" maxOccurs="1"/> </choice> </sequence> </group> <!-- ****************** Server Propagation Group ****************** --> <group name="server_prop_operation"> <sequence> <element ref="aq:server_prop_operation" minOccurs="0" maxOccurs="1"/> <choice> <element ref="aq:push" maxOccurs="1"/> <element ref="aq:notification" maxOccurs="1"/> <element ref="aq:sequence_num_request" maxOccurs="1"/> </choice> </sequence> </group> <!-- ****************** Client Operation ****************** --> <element name="client_operation"> <complexType content="mixed"> <element ref="aq:txid" minOccurs="0"/> <attribute name="opcode" use="required" type="aq:opcode_type"/> </complexType> </element> <!-- ****************** Server Response ****************** --> <element name="server_response"> <complexType content="mixed"> <element ref="aq:txid" minOccurs="0"/> <element ref="aq:status_response" minOccurs="1"/> <attribute name="opcode" use="required" type="aq:opcode_type"/> </complexType> </element> <!-- ****************** Server Propagation Operation ****************** --> <element name="server_prop_operation"> <complexType content="mixed"> <element ref="aq:txid" minOccurs="0"/> <attribute name="prop_opcode" use="required" type="aq:prop_opcode_type"/> </complexType> </element> <element name="txid" type="string"/> .... <!-- ****************** Message payload ****************** --> <element name="message_payload"> <complexType> <choice> <element ref="aq:jms_text_message" minOccurs="0" maxOccurs="1"/> <element ref="aq:jms_map_message" minOccurs="0" maxOccurs="1"/> <element ref="aq:jms_bytes_message" minOccurs="0" maxOccurs="1"/> <element ref="aq:jms_object_message" minOccurs="0" maxOccurs="1"/> <any minOccurs="0" maxOccurs="*" processContents="skip"/> </choice> </complexType> </element> <!-- ****************** User-defined properties ****************** --> <element name="user_properties"> <complexType content="mixed"> <element ref="aq:property" minOccurs="0" maxOccurs="*"/> </complexType> </element> <!-- ****************** Property ****************** --> <element name="property"> <complexType content="mixed"> <element ref="aq:name" minOccurs="1" maxOccurs="1"/> <element ref="aq:value" minOccurs="1" maxOccurs="1"/> <attribute name="property_type" type="aq:prop_type"/> </complexType> </element> <!-- ****************** Status response ****************** --> <element name="status_response"> <complexType content="mixed"> <element ref="aq:acknowledge" minOccurs="0" maxOccurs="1"/> <element ref="aq:status_code" minOccurs="0" maxOccurs="1"/> <element ref="aq:error_code" minOccurs="0" maxOccurs="1"/> <element ref="aq:error_message" minOccurs="0" maxOccurs="1"/> </complexType> </element> <!-- ****************** Send result ****************** --> <element name="send_result"> <complexType content="mixed"> <element ref="aq:destination" minOccurs="1" maxOccurs="1"/> <element ref="aq:message_id" minOccurs="0" maxOccurs="*"/> </complexType> </element> <!-- ****************** Publish result ****************** --> <element name="publish_result"> <complexType content="mixed"> <element ref="aq:destination" minOccurs="1" maxOccurs="1"/> <element ref="aq:message_id" minOccurs="0" maxOccurs="*"/> </complexType> </element> <!-- ****************** Receive result ****************** --> <element name="receive_result"> <complexType content="mixed"> <element ref="aq:destination" minOccurs="1" maxOccurs="1"/> <element ref="aq:message_set" minOccurs="0" maxOccurs="*"/> </complexType> </element> . . <!-- ****************** JMS text message ****************** --> <element name="jms_text_message"> <complexType content="mixed"> <element ref="aq:oracle_jms_properties" minOccurs="0" maxOccurs="1"/> <element ref="aq:user_properties" minOccurs="0" maxOccurs="1"/> <element ref="aq:text_data" minOccurs="1" maxOccurs="1"/> </complexType> </element> <element name="text_data" type="string"/> <!-- ****************** JMS map message ****************** --> <element name="jms_map_message"> <complexType content="mixed"> <element ref="aq:oracle_jms_properties" minOccurs="0" maxOccurs="1"/> <element ref="aq:user_properties" minOccurs="0" maxOccurs="1"/> <element ref="aq:map_data" minOccurs="1" maxOccurs="1"/> </complexType> </element> <!-- ****************** Map data ****************** --> <element name="map_data"> <complexType content="mixed"> <element ref="aq:item" minOccurs="0" maxOccurs="*"/> </complexType> </element> <!-- ****************** Map Item ****************** --> <element name="item"> <complexType content="mixed"> <element ref="aq:name" minOccurs="1" maxOccurs="1"/> <element ref="aq:value" minOccurs="1" maxOccurs="1"/> <attribute name="item_type" type="aq:prop_type"/> </complexType> </element> <!-- ****************** JMS bytes message ****************** --> <element name="jms_bytes_message"> <complexType content="mixed"> <element ref="aq:oracle_jms_properties" minOccurs="0" maxOccurs="1"/> <element ref="aq:user_properties" minOccurs="0" maxOccurs="1"/> <element ref="aq:bytes_data" minOccurs="1" maxOccurs="1"/> </complexType> </element> <element name="bytes_data" type="string"/> <!-- ****************** JMS object message ****************** --> <element name="jms_object_message"> <complexType content="mixed"> <element ref="aq:oracle_jms_properties" minOccurs="0" maxOccurs="1"/> <element ref="aq:user_properties" minOccurs="0" maxOccurs="1"/> <element ref="aq:ser_object_data" minOccurs="1" maxOccurs="1"/> </complexType> </element> <element name="ser_object_data" type="string"/> </schema>
<AQXmlDocument xmlns="http://www.oracle.com/AQXmlDocument" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xsi:schemaLocation="http://www.oracle.com/AQXmlDocument aq.xsd"> <client_operation opcode="SEND"> <txid> sdasdfdsf </txid> </client_operation> <producer_options delivery_mode="PERSISTENT"> <destination lookup_type="NORMAL"> queue1 </destination> <priority>23</priority> <recipient_list> <recipient> abc </recipient> <recipient lookup_type="LDAP"> abc </recipient> </recipient_list> </producer_options> <message_set> <message_count>1</message_count> <message> <message_number>1</message_number> <message_header> <correlation>XML_40_NEW_TEST</correlation> <delay>10</delay> <sender_id>scott::home::0</sender_id> </message_header> <message_payload> <jms_map_message> <oracle_jms_properties> <reply_to>oracle::redwoodshores::100</reply_to> <userid>scott</userid> <appid>AQProduct</appid> <groupid>AQ</groupid> </oracle_jms_properties> <user_properties> <property property_type="STRING"> <name>country</name> <value>USA</value> </property> <property property_type="STRING"> <name>State</name> <value>california</value> </property> </user_properties> <map_data> <item item_type="STRING"> <name>Car</name> <value>Toyota</value> </item> <item item_type="STRING"> <name>Color</name> <value>Blue</value> </item> <item item_type="STRING"> <name>Shape</name> <value>Circle</value> </item> <item item_type="NUMBER"> <name>Price</name> <value>20000</value> </item> </map_data> </jms_map_message> </message_payload> </message> </message_set> </AQXmlDocument>
XML C++ Schema processor Initializing XML package... Parsing 'aq.xml'... Initializing Schema package... Validating document... Document is valid.
<?xml version="1.0"?> <schema xmlns = "http://www.w3.org/2000/08/XMLSchema" targetNamespace = "http://www.somewhere.org/BookCatalogue" xmlns:cat = "http://www.somewhere.org/BookCatalogue" elementFormDefault="qualified"> <complexType name="Pub"> <sequence> <element name="Title" type="cat:titleType" maxOccurs="*"/> <element name="Author" type="string" maxOccurs="*"/> <element name="Date" type="date"/> </sequence> <attribute name="language" type="string" use="default" value="English"/> <anyAttribute namespace="##local"/> </complexType> <element name="Publication" type="cat:Pub" abstract="true"/> <element name="Book" substitutionGroup="cat:Publication"> <complexType> <complexContent> <extension base="cat:Pub" > <sequence> <element name="ISBN" type="string" default="123456789"/> <element name="Publisher" type="string"/> </sequence> </extension> </complexContent> </complexType> </element> <complexType name="titleType"> <simpleContent> <extension base="string" > <attribute name="old" type="string" use="default" value="false"/> </extension> </simpleContent> </complexType> <element name="Magazine" substitutionGroup="cat:Publication"> <complexType> <complexContent> <extension base="cat:Pub"> <sequence> <element name="Volume" type="cat:VolumeType"/> <element name="htmlTable"> <complexType> <any namespace="##other" processContents="skip" minOccurs="0" maxOccurs="2"/> </complexType> </element> </sequence> </extension> </complexContent> </complexType> </element> <simpleType name="VolumeType"> <restriction base="integer" > <minInclusive value = "1"/> <maxInclusive value = "12"/> </restriction> </simpleType> <element name="Catalogue"> <complexType> <sequence> <element ref="cat:Publication" minOccurs="0" maxOccurs="*"/> </sequence> </complexType> </element> </schema>
<?xml version="1.0"?> <Catalogue xmlns = "http://www.somewhere.org/BookCatalogue" xmlns:cat = "http://www.somewhere.org/BookCatalogue" xmlns:html = "http://www.somewhere.org/HTMLCatalogue" xmlns:xsi = "http://www.w3.org/1999/XMLSchema-instance" xsi:schemaLocation = "http://www.somewhere.org/BookCatalogue pub.xsd"> <cat:Magazine> <Title>Natural Health</Title> <Author>October</Author> <Date>1999-12</Date> <Volume>12</Volume> <htmlTable> <table xmlns = "http://www.somewhere.org/HTMLCatalogue"> <tr>....</tr> </table> <html:table> <html:tr>....</html:tr> </html:table> </htmlTable> </cat:Magazine> <Book> <Title>Illusions The Adventures of a Reluctant Messiah</Title> <Author>Richard Bach</Author> <Date>1977</Date> <ISBN></ISBN> <Publisher>Dell Publishing Co.</Publisher> </Book> <Book> <Title>The First and Last Freedom</Title> <Author>J. Krishnamurti</Author> <Date>1954</Date> <ISBN>0-06-064831-7</ISBN> <Publisher>Harper & Row</Publisher> </Book> </Catalogue>
XML C++ Schema processor Initializing XML package... Parsing 'pub.xml'... Initializing Schema package... Validating document... Document is valid.
|
![]() Copyright © 1996-2001, Oracle Corporation. All Rights Reserved. |
|