Oracle® XML Developer's Kit Programmer's Guide 10g Release 2 (10.2) Part Number B14252-01 |
|
|
View PDF |
The XDK C components are the building blocks for reading, manipulating, transforming, and validating XML.
This chapter contains the following topics:
The C XDK components are included with Oracle Database. This chapter assumes that you have installed XDK with Oracle Database and also installed the demo programs on the Oracle Database Companion CD. Refer to "Installing the XDK" for installation instructions and a description of the XDK directory structure.
Example 14-1 shows the UNIX directory structure for the XDK demos and the libraries used by the XDK components. The $ORACLE_HOME/xdk/demo/c
subdirectories contain sample programs and data files for the XDK for C components. The chapters in Part II, "XDK for C" explain how to understand and use these programs.
Example 14-1 C XDK Libraries, Header Files, Utilities, and Demos
- Oracle_home_directory | - bin/ schema xml xmlcg xsl xvm | - lib/ libcore10.a libcoresh10.so libnls10.a libunls10.a libxml10.a
| - xdk/ | demo/ | - c/ | - dom/ | - parser/ | - sax/ | - schema/ | - webdav/ | - xslt/ | - xsltvm/ | include/ oratypes.h oraxml.h oraxmlcg.h oraxsd.h xml.h xmlerr.h xmlotn.h xmlproc.h xmlsch.h xmlxptr.h xmlxsl.h xmlxvm.h
The subdirectories contain sample programs and data files for the C XDK components. The chapters in Part II, "XDK for C" explain how to use these programs to gain an understanding of the most important C features.
See Also:
"Overview of Oracle XML Developer's Kit (XDK)" for a list of the XDK C componentsThis section contains the following topics:
The C libraries described in this section are located in $ORACLE_HOME/lib
. The XDK C and C++ components are contained in the following library:
libxml10.a
The following XDK components are contained in the library:
XML parser, which checks an XML document for well-formedness, optionally validates it against a DTD or XML Schema, and supports DOM and SAX interfaces for programmatic access
XSLT processor, which transforms an XML document into another XML document
XSLT compiler, which compiles XSLT stylesheets into byte code for use by the XSLT Virtual Machine
XSLTVM, which is an XSLT transformation engine
XML Schema processor, which validates XML files against an XML schema
Table 14-1 describes the Oracle CORE and Globalization Support libraries on which the XDK C components (UNIX) depend.
Table 14-1 Dependent Libraries of XDK C Components on UNIX
Component | Library | Description |
---|---|---|
CORE library | libcore10.a |
Contains the C runtime functions that enable portability across platforms. |
CORE Dynamic linking library | libcoresh10.so |
C runtime library that supports dynamic linking on UNIX platforms. |
Globalization Support common library | libnls10.a |
Supports the UTF-8, UTF-16, and ISO-8859-1 character sets. This library depends on the environment to locate encoding and message files. |
Globalization Support library for Unicode | libunls10.a |
Supports the character sets described in Oracle Database Globalization Support Guide. This library depends on the environment to locate encoding and message files. |
Table 14-2 describes the UNIX environment variables required for use with the XDK C components.
Table 14-2 UNIX Environment Settings for XDK C Components
Variable | Description | Setting |
---|---|---|
$ORA_NLS10 |
Sets the location of the Globalization Support character-encoding definition files. The encoding files represent a subset of character sets available in Oracle Database. | Set to the location of the Globalization Support data files. Set the variable as follows:
setenv ORA_NLS10 $ORACLE_HOME/nls/data |
$ORA_XML_MESG |
Sets the location of the XML error message files. Files ending in .msb are machine-readable and required at runtime. Files ending in .msg are human-readable and contain cause and action descriptions for each error. |
Set to the path of the mesg directory. For example:
setenv ORA_XML_MESG $ORACLE_HOME/xdk/mesg |
$PATH |
Sets the location of the C XDK executables. | You can set the PATH as follows:
setenv PATH ${PATH}:${ORACLE_HOME}/bin |
You can test your UNIX runtime environment by running any of the utilities described in Table 14-3.
Table 14-3 C/C++ XDK Utilities on UNIX
Executable | Directory | Description |
---|---|---|
schema |
$ORACLE_HOME/bin |
C XML Schema validator
See Also: "Using the C XML Schema Processor Command-Line Utility" |
xml |
$ORACLE_HOME/bin |
C XML parser |
xmlcg |
$ORACLE_HOME/bin |
C++ class generator
See Also: "Using the XML C++ Class Generator Command-Line Utility" |
xsl |
$ORACLE_HOME/bin |
C XSLT processor |
xvm |
$ORACLE_HOME/bin |
C XVM processor |
Run these utilities with no options to display the usage help. Run the utilities with the -hh
flag for complete usage information.
Table 14-4 describes the header files required for compilation of the C components. These files are located in $ORACLE_HOME/xdk/include
. Note that your runtime environment must be set up before you can compile your code.
Table 14-4 Header Files in the C XDK Compile-Time Environment
Header File | Description |
---|---|
oratypes.h |
Includes the private Oracle C datatypes. |
oraxml.h |
Includes the Oracle9i XML ORA datatypes and the public ORA APIs included in libxml.a (for backward compatibility only). Use xml.h instead. |
oraxmlcg.h |
Includes the C APIs for the C++ class generator (for backward compatibility only). |
oraxsd.h |
Includes the Oracle9i XSD validator datatypes and APIs (for backward compatibility only). |
xml.h |
Handles the unified DOM APIs transparently, whether you use them through OCI or standalone. It replaces oraxml.h , which is deprecated. |
xmlerr.h |
Includes the XML errors and their numbers. |
xmlotn.h |
Includes the other headers depending on whether you compile standalone or use OCI. |
xmlproc.h |
Includes the Oracle 10g XML datatypes and XML public parser APIs in libxml10.a . |
xmlsch.h |
Includes the Oracle 10g XSD validator public APIs. |
xmlptr.h |
Includes the XPointer datatypes and APIs, which are not currently documented or supported. |
xmlxsl.h |
Includes the XSLT processor datatypes and public APIs. |
xmlxvm.h |
Includes the XSLT compiler and VM datatypes and public APIs. |
The simplest way to test your compile-time environment is to run the make
utility on the sample programs, which are located on the Companion CD rather than on the Oracle Database 10g CD. After you install the demos, they will be located in $ORACLE_HOME/xdk/demo/c
. A README
in the same directory provides compilation instructions and usage notes.
Build and run the sample programs by executing the following commands at the system prompt:
cd $ORACLE_HOME/xdk/demo/c make
This section contains the following topics:
The C libraries described in this section are located in %ORACLE_HOME%\lib
. The XDK C components are contained in the following library:
libxml10.dll
The following XDK components are contained in the library:
XML parser
XSLT processor
XSLT compiler
XSLT VM
XML Schema processor
Table 14-5 describes the Oracle CORE and Globalization Support libraries on which the XDK C components (Windows) depend.
Table 14-5 Dependent Libraries of XDK C Components on Windows
Component | Library | Description |
---|---|---|
CORE library | libcore10.dll |
Contains the runtime functions that enable portability across platforms. |
Globalization Support common library | libnls10.dll |
Supports the UTF-8, UTF-16, and ISO-8859-1 character sets. This library depends on the environment to find encoding and message files. |
Globalization Support library for Unicode | libunls10.dll |
Supports the character sets described in Oracle Database Globalization Support Guide. This library depends on the environment to find encoding and message files. |
Table 14-6 describes the Windows environment variables required for use with the XDK C components.
Table 14-6 Windows Environment Settings for C XDK Components
Variable | Description | Setting |
---|---|---|
%ORA_NLS10% |
Sets the location of the Globalization Support character-encoding definition files. The encoding files represent a subset of character sets available in Oracle Database. | This variable should be set to the location of the Globalization Support data files. Set the variable as follows:
set ORA_NLS10=%ORACLE_HOME%\nls\data |
%ORA_XML_MESG% |
Sets the location of the XML error message files. Files ending in .msb are machine-readable and required at runtime. Files ending in .msg are human-readable and contain cause and action descriptions for each error. |
Set to the path of the mesg directory. For example:
set ORA_XML_MESG=%ORACLE_HOME%\xdk\mesg |
%PATH% |
Sets the location of the C XDK DLLs and executables. | You can set the PATH as follows:
path %path%;%ORACLE_HOME%\bin |
You can test your Windows runtime environment by running any of the utilities described in Table 14-7.
Table 14-7 C/C++ XDK Utilities on Windows
Executable | Directory | Description |
---|---|---|
schema.exe |
%ORACLE_HOME%\bin |
C XML Schema validator
See Also: "Using the C XML Schema Processor Command-Line Utility" |
xml.exe |
%ORACLE_HOME%\bin |
C XML parser |
xmlcg.exe |
%ORACLE_HOME%\bin |
C++ class generator
See Also: "Using the XML C++ Class Generator Command-Line Utility" |
xsl.exe |
%ORACLE_HOME%\bin |
C XSLT processor |
xvm.exe |
%ORACLE_HOME%\bin |
C XVM processor |
Run these utilities with no options to display the usage help. Run the utilities with the -hh
flag for complete usage information.
Table 14-4 in the section "Setting Up and Testing the C XDK Compile-Time Environment on UNIX" describes the header files required for compilation of the C components on Windows. The relative filenames are the same on both UNIX and Windows installations.
On Windows the header files are located in %ORACLE_HOME%\xdk\include
. Note that you must set up your runtime environment before you can compile your code.
You can test your compile-time environment by compiling the demo programs, which are located in %ORACLE_HOME%\xdk\demo\c
after you install them from the Oracle 10g Database Companion CD. A README in the same directory provides compilation instructions and usage notes.
The demo make.bat
file assumes that you are using the cl.exe
compiler, which is freely available with the Microsoft .NET Framework Software Development Kit (SDK).
To set the path for the cl.exe
compiler on Windows XP, follow these steps:
In the Start menu, select Settings and then Control Panel.
Double-click System.
In the System Properties dialogue box, select the Advanced tab and click Environment Variables.
In System variables, select Path and click Edit.
Append the path of cl.exe
to the %PATH%
variable as shown in Figure 14-1 and click OK.
Each subfolder of the %ORACLE_HOME%\xdk\demo\c
folder contains a Make.bat
file. Update the Make.bat
file in each folder by adding the path of the libraries and the header files to the compile command. You should not need to edit the paths in the :LINK
section because /libpath:%ORACLE_HOME%\lib
already points to the C libraries. The section of a Make.bat
file in Example 14-1 uses bold text to show the path that you need to include.
Example 14-2 Editing a C XDK Make.bat File on Windows
:COMPILE
set filename=%1
cl -c -Fo%filename%.obj %opt_flg% /DCRTAPI1=_cdecl /DCRTAPI2=_cdecl /nologo /Zl
/Gy /DWIN32 /D_WIN32 /DWIN_NT /DWIN32COMMON /D_DLL /D_MT /D_X86_=1
/Doratext=OraText -I. -I..\..\..\include -I%ORACLE_HOME%\xdk\include %filename%.c
goto :EOF
:LINK
set filename=%1
link %link_dbg% /out:..\..\..\..\bin\%filename%.exe
/libpath:%ORACLE_HOME%\lib /libpath:..\..\..\..\lib
%filename%.obj oraxml10.lib user32.lib kernel32.lib msvcrt.lib ADVAPI32.lib
oldnames.lib winmm.lib
You can set up a project in Microsoft Visual C/C++ and use it for the demos included in the XDK.
Follow these steps to set the path for a project:
Open a workspace in Visual C++ and include the *.c
files for your project.
Navigate to the Tools menu and select Options.
Select the Directories tab and set your include path to %ORACLE_HOME%\xdk\include
as shown in the example in Figure 14-2.
Follow these steps to set the library path for a project:
Open a workspace in Visual C++ and include the *.c
files for your project.
Navigate to the Tools menu and select Options.
Select the Directories tab and set your library path to %ORACLE_HOME%\lib
as shown in the example in Figure 14-3.
After setting the paths for the static libraries in %ORACLE_HOME%\lib
, set the library name in the compiling environment of Visual C++. Navigate to the Project menu in the menu bar and select Settings.
Select the Link tab in the Object/Library Modules field and enter the names of XDK C components libraries, as shown in the example in Figure 14-4.
Figure 14-4 Setting the Names of the Libraries in Visual C/C++ Project
The unified C API is a programming interface that centralizes the functionality required by the XDK and Oracle XML DB. XSLT and XML Schema are primary customers of the API.
As shown in Table 14-4, the unified C API is declared in xml.h
, which replaces the oraxml.h
file used in releases prior to Oracle Database 10g. Table 14-8 summarizes the C XDK API. Refer to Oracle XML API Reference for the complete API documentation.
Table 14-8 Summary of the XDK C API
Package | Purpose |
---|---|
Callback APIs | Define macros that declare functions (or function pointers) for XML callbacks. |
DOM APIs | Parse and manipulate XML documents with DOM. The API follows the DOM 2.0 standard as closely as possible, although it changes some names when mapping from the objected-oriented DOM specification to the flat C namespace. For example, the overloaded getName() methods become getAttrName() . |
Range APIs | Create and manipulate Range objects. |
SAX APIs | Enable event-based XML parsing with SAX. |
Schema APIs | Assemble multiple XML schema documents into a single schema that can be used to validate a specific instance document. |
Traversal APIs | Enable document traversal and navigation of DOM trees. |
XML APIs | Define an XML processor in terms of how it must read XML data and the information it must provide to the application. |
XPath APIs | Process XPath-related types and interfaces. |
XPointer APIs | Locate nodes in an XML document. |
XSLT APIs | Perform XSL processing. |
XSLTVM APIs | Implement a virtual machine that can run compiled XSLT code. |
The API accomplishes the unification of the functions by conforming contexts. A top-level XML context (xmlctx
) shares common information between cooperating XML components. This context defines information such as the following:
Data encoding
Error message language
Low-level allocation callbacks
An application needs this information before it can parse a document and provide programmatic access through DOM or SAX.
Both the XDK and the Oracle XML DB required different startup and tear-down functions for the top-level and service contexts. The initialization function takes implementation-specific arguments and returns a conforming context. A conforming context means that the returned context must begin with a xmlctx
; it may have any additional implementation-specific parts after the standard header.
Initialization, which is the acquisition of an xmlctx
, is an implementation-specific step. After an application obtains xmlctx
, it uses unified DOM calls, all of which take an xmlctx
as the first argument.
The unified interface supersedes the C API in releases prior to Oracle Database 10g. In particular, the XDK has deprecated the oraxml
interfaces (top-level, DOM, SAX and XSLT) and oraxsd
(Schema) interfaces.
The C XDK parser supports over 300 IANA character sets. These character sets include those listed in "Character Sets Supported by the XDK for C". Note the following considerations when working with character sets:
It is recommended that you use IANA character set names for interoperability with other XML parsers.
XML parsers are only required to support UTF-8 and UTF-16, so these character sets are preferable.
The default input encoding ("incoding") is UTF-8. If an input document's encoding is not self-evident (by HTTP character set, Byte Order Mark, XMLDecl, and so on), then the default input encoding is assumed. 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 because single-byte performance is fastest. The flag XML_FLAG_FORCE_INCODING
specifies that the default input encoding should always be applied to input documents, ignoring any BOM or XMLDecl. Nevertheless, a protocol declaration such as HTTP character set is always honored.
Choose the data encoding for DOM and SAX ("outcoding") carefully. Single-byte encodings are the fastest, but can represent only a very limited set of characters. Next fastest is Unicode (UTF-16), and slowest are the multibyte encodings such as UTF-8. If input data cannot be converted to the outcoding without loss, then an error occurs. For maximum utility, you should use a Unicode-based outcoding because Unicode can represent any character. If outcoding is not specified, then it defaults to the incoding of the first document parsed.