This chapter explains how to get started with Oracle XML Developer's Kit (XDK) for C.
XDK for C components are the building blocks for reading, manipulating, transforming, and validating Extensible Markup Language (XML).
The XDK for C 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 Examples media. See "Installing XDK" for installation instructions and a description of the XDK directory structure.
The following set of examples shows the UNIX directory structure for the XDK demos and the libraries used by the XDK components. The subdirectories contain sample programs and data files for the XDK for C components.
Example 18-1 lists the main directories under the Oracle home directory for C.
Example 18-1 Oracle XML Developer's Kit for C Libraries, Header Files, Utilities, and Demos
- $ORACLE_HOME | - bin/ | - lib/ | - xdk/
The contents of each subdirectory under this main directory are listed individually.
The bin
directory contains these components:
schema xml xmlcg xsl xvm
The lib
directory contains these components:
libcore11.a libcoresh11.so libnls11.a libunls11.a libxml11.a libxmlsh10.a
The xdk
directory contains this demo
subdirectory:
| demo/ | - c/ | - dom/ | - parser/ | - sax/ | - schema/ | - webdav/ | - xslt/ | - xsltvm/
The /xdk/demo/c
subdirectories contain sample programs and data files for XDK for C components. The chapters in Part II, "Oracle XML Developer's Kit for C" explain how to use these programs to gain an understanding of the most important C features.
The xdk
directory also contains this include
subdirectory:
| 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
Table 18-4 in "Setting Up and Testing the XDK C Compile-Time Environment on UNIX" describes the C header files.
See Also:
"Overview of XDK" for a list of the XDK for C componentsThe C libraries described in this section are located in $ORACLE_HOME/lib
. XDK for C and C++ components are contained in this library:
libxml11.a
The following XKD components are contained in the library:
XML parser, which checks an XML document for well-formedness, optionally validates it against a document type definition (DTD) or XML Schema, and supports Document Object Model (DOM) and Simple API for XML (SAX) interfaces for programmatic access
Extensible Stylesheet Language Transformation (XSLT) processor, which transforms an XML document into another XML document
XSLT compiler, which compiles XSLT style sheets into byte code for use by the XSLT Virtual Machine (XSLT VM)
XSLTVM, which is an XSLT transformation engine
XML Schema processor, which validates XML files against an XML schema
Table 18-1 describes the Common Oracle Runtime Environment (CORE) and Globalization Support libraries on which XDK for C components (UNIX) depend.
Table 18-1 Dependent Libraries of Oracle XML Developer's Kit for C Components on UNIX
Component | Library | Description |
---|---|---|
CORE library |
|
Contains the C runtime functions that enable portability across platforms. |
CORE Dynamic linking library |
|
C runtime library that supports dynamic linking on UNIX platforms. |
Globalization Support common library |
|
Supports the 8-bit encoding of Unicode (UTF-8), 16-bit encoding of Unicode (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 |
|
Supports the character sets described in Oracle Database Globalization Support Guide. This library depends on the environment to locate encoding and message files. |
Table 18-2 describes the UNIX environment variables required for use with XDK for C components.
Table 18-2 UNIX Environment Settings for Oracle XML Developer's Kit for C Components
Variable | Description | Setting |
---|---|---|
|
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: setenv ORA_NLS10 $ORACLE_HOME/nls/data |
|
Sets the location of the XML error message files. Files ending in |
Set to the path of the setenv ORA_XML_MESG $ORACLE_HOME/xdk/mesg |
|
Sets the location of the XDK for C executables. |
Set the setenv PATH ${PATH}:${ORACLE_HOME}/bin |
You can test XDK for C in your UNIX runtime environment by running any of the utilities described in Table 18-3.
Table 18-3 Oracle XML Developer's Kit for C/C++ Utilities on UNIX
Executable | Directory | Description |
---|---|---|
|
|
C XML Schema validator See Also: "Using the C XML Schema Processor Command-Line Utility" |
|
|
C XML parser |
|
|
C++ class generator See Also: "Using the XML C++ Class Generator Command-Line Utility" |
|
|
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 18-4 describes the header files required for compilation of XDK for C components. These files are located in $ORACLE_HOME/xdk/include
. Your runtime environment must be set up before you can compile your code.
Table 18-4 Header Files in the Oracle XML Developer's Kit for C Compile-Time Environment
Header File | Description |
---|---|
|
Includes the private Oracle C data types. |
|
Includes the Oracle9i XML Open Reporting Application (ORA) data types and the public ORA APIs included in |
|
Includes the C APIs for the C++ class generator (only for backward compatibility). |
|
Includes the Oracle9i XML schema definition (XSD) validator data types and application programming interfaces (APIs)—only for backward compatibility. |
|
Handles the unified DOM APIs transparently, whether you use them through Oracle Call Interface (OCI) or standalone. It replaces |
|
Includes the XML errors and their numbers. |
|
Includes the other headers depending on whether you compile standalone or use OCI. |
|
Includes the Oracle XML data types and XML public parser APIs in |
|
Includes the Oracle XSD validator public APIs. |
|
Includes the XPointer data types and APIs, which are not currently documented or supported. |
|
Includes the XSLT processor data types and public APIs. |
|
Includes the XSLT compiler and VM data types and public APIs. |
The simplest way to test XDK for C in your compile-time environment is to run the make
utility on the sample programs, which are located on the Examples media rather than on the Oracle Database CD. After installing the demos, they are 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 these commands at the system prompt:
cd $ORACLE_HOME/xdk/demo/c make
Setting Up and Testing the XDK for C Compile-Time Environment on Windows
Using the XDK for C Components and Visual C++ in Microsoft Visual Studio
The C libraries described in this section are located in %ORACLE_HOME%\lib
. XDK for C components are contained in this library:
libxml11.dll
The following XDK components are contained in the library:
XML parser
XSLT processor
XSLT compiler
XSLT VM
XML Schema processor
Table 18-5 describes the Oracle CORE and Globalization Support libraries on which XDK for C components (Windows) depend.
Table 18-5 Dependent Libraries of Oracle XML Developer's Kit for C Components on Windows
Component | Library | Description |
---|---|---|
CORE library |
|
Contains the runtime functions that enable portability across platforms. |
Globalization Support common library |
|
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 |
|
Supports the character sets described in Oracle Database Globalization Support Guide. This library depends on the environment to find encoding and message files. |
Table 18-6 describes the Windows environment variables required for use with the XDK for C components.
Table 18-6 Windows Environment Settings for Oracle XML Developer's Kit for C Components
Variable | Description | Setting |
---|---|---|
|
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 must be set to the location of the Globalization Support data files. Set the variable: set ORA_NLS10=%ORACLE_HOME%\nls\data |
|
Sets the location of the XML error message files. Files ending in |
Set to the path of the set ORA_XML_MESG=%ORACLE_HOME%\xdk\mesg |
|
Sets the location of the XDK for C data definition languages (DLLs) and executables. |
Set the path %path%;%ORACLE_HOME%\bin |
You can test XDK in your Windows runtime environment by running any of the utilities described in Table 18-7.
Table 18-7 Oracle XML Developer's Kit for C/C++ Utilities on Windows
Executable | Directory | Description |
---|---|---|
|
|
C XML Schema validator See Also: "Using the C XML Schema Processor Command-Line Utility" |
|
|
C XML parser |
|
|
C++ class generator See Also: "Using the XML C++ Class Generator Command-Line Utility" |
|
|
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 18-4 in the section "Setting Up and Testing the XDK C Compile-Time Environment on UNIX" describes the header files required for compilation of the C components on Windows. The relative file names are the same on both UNIX and Windows installations.
On Windows the header files are located in %ORACLE_HOME%\xdk\include
. You must set up your runtime environment before you can compile your code.
You can test XDK for C in 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 Database Examples media. A README
file in the same directory provides compilation instructions and usage notes. Before you compile the demo programs, edit the Make.bat
files as described in "Editing the Make.bat Files on Windows."
Each subfolder of the %ORACLE_HOME%\xdk\demo\c
folder contains a file Make.bat
. Update the Make.bat
file in each folder by adding the path of the libraries and the header files to the compile command. You do not have 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 18-2 uses bold text to show the path that you must include.
Example 18-2 Editing an Oracle XML Developer's Kit for C 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
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 and click OK.
Build and run the sample programs by executing these commands at the system prompt:
cd $ORACLE_HOME/xdk/demo/c make
You can set up a project with a Visual C++ template and use it for the demos included in XDK.
Follow these steps to set the path for a project:
Open a project in Visual C++ and include the *.c
files for your project.
Navigate to the Project menu and select Properties.
When Property Pages appear, expand Configuration Properties and select VC++ Directories.
Under General on the right side, select Include Directories.
Click the arrow at the end of the line, and select the second line, which reads <Edit...>.
When the Include Directories window appears, click New Line from the tool bar and enter this include path, %ORACLE_HOME%\xdk\include
, as shown in the example in Figure 18-2 and click OK.
Figure 18-2 Setting the Include Path in Visual C++
Follow these steps to set the library path for a project:
Open a project in Visual C++ and include the *.c
files for your project.
Navigate to the Project menu and select Properties.
When Property Pages appear, expand Configuration Properties and select VC++ Directories.
Under General on the right side, select Library Directories.
Click the arrow at the end of the line, and select the second line which reads <Edit...>.
When the Library Directories window appears, click New Line from the tool bar and enter this library path, %ORACLE_HOME%\lib
, as shown in the example in Figure 18-3 and click OK.
Figure 18-3 Setting the Static Library Path in Visual C++
After setting the paths for the static libraries in %ORACLE_HOME%\lib
, navigate to the Project menu and select Properties.
In the Properties Page, select and expand Linker under Configuration Properties, and select Input.
Select Additional Dependencies and click the arrow at the end of the line. Select the second line which reads <Edit...>.
Enter these additional dependencies: oraxml9.lib
, oraxmlg9.lib
, and oraxsd9.lib
as shown in Figure 18-4 and click OK.
Figure 18-4 Setting the Names of the Libraries in Visual C++ Project
The unified C API is a programming interface that unifies the functionality required by both XDK for C and Oracle XML DB. This API is used primarily by XSLT and XML Schema.
As shown in Table 18-4, the unified C API is declared in the xml.h
header file. Table 18-8 summarizes the XDK for C APIs. See Oracle Database XML C API Reference for complete documentation.
Table 18-8 Summary of Oracle XML Developer's Kit for C APIs
Package | Purpose |
---|---|
Define macros that declare functions (or function pointers) for XML callbacks. |
|
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 |
|
Create and manipulate |
|
Enable event-based XML parsing with SAX. |
|
Assemble multiple XML schema documents into a single schema that can be used to validate a specific instance document. |
|
Enable document traversal and navigation of DOM trees. |
|
Define an XML processor in terms of how it must read XML data and the information it must provide to the application. |
|
Process XPath-related types and interfaces. |
|
Locate nodes in an XML document. |
|
Perform XSL processing. |
|
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 about:
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 interfaces.
Both XDK for C and Oracle XML DB require 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.
The unification is made possible by using conforming contexts. 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.
After an application gets xmlctx
, it uses unified DOM invocations, all of which take an xmlctx
as the first argument.
The XDK for C parser supports over 300 IANA character sets. These character sets include those listed in "Character Sets Supported by XDK for C."
Considerations when working with character sets:
Oracle recommends that you use Internet Assigned Numbers Authority (IANA) character set names for interoperability with other XML parsers.
XML parsers are required only 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 (BOM), XMLDecl, and so on), then the default input encoding is assumed. Oracle recommends 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 is always 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, 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.