Oracle® XML Developer's Kit Programmer's Guide, 11g Release 2 (11.2) Part Number E10708-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 Examples media. Refer to "Installing the XDK" for installation instructions and a description of the XDK directory structure.
Example 16-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 16-1 C XDK Libraries, Header Files, Utilities, and Demos
- Oracle_home_directory | - bin/ schema xml xmlcg xsl xvm | - lib/ libcore11.a libcoresh11.so libnls11.a libunls11.a libxml11.a libxmlsh10.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:
libxml11.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 16-1 describes the Oracle CORE and Globalization Support libraries on which the XDK C components (UNIX) depend.
Table 16-1 Dependent Libraries of XDK 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 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 |
|
Supports the character sets described in Oracle Database Globalization Support Guide. This library depends on the environment to locate encoding and message files. |
Table 16-2 describes the UNIX environment variables required for use with the XDK C components.
Table 16-2 UNIX Environment Settings for XDK 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 as follows: 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 C XDK executables. |
You can set the setenv PATH ${PATH}:${ORACLE_HOME}/bin |
You can test your UNIX runtime environment by running any of the utilities described in Table 16-3.
Table 16-3 C/C++ XDK 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 XSLT processor |
|
|
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 16-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 16-4 Header Files in the C XDK Compile-Time Environment
Header File | Description |
---|---|
|
Includes the private Oracle C datatypes. |
|
Includes the Oracle9i XML ORA datatypes and the public ORA APIs included in |
|
Includes the C APIs for the C++ class generator (for backward compatibility only). |
|
Includes the Oracle9i XSD validator datatypes and APIs (for backward compatibility only). |
|
Handles the unified DOM APIs transparently, whether you use them through 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 datatypes and XML public parser APIs in |
|
Includes the Oracle XSD validator public APIs. |
|
Includes the XPointer datatypes and APIs, which are not currently documented or supported. |
|
Includes the XSLT processor datatypes and public APIs. |
|
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 Examples media rather than on the Oracle Database 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:
libxml11.dll
The following XDK components are contained in the library:
XML parser
XSLT processor
XSLT compiler
XSLT VM
XML Schema processor
Table 16-5 describes the Oracle CORE and Globalization Support libraries on which the XDK C components (Windows) depend.
Table 16-5 Dependent Libraries of XDK 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 16-6 describes the Windows environment variables required for use with the XDK C components.
Table 16-6 Windows Environment Settings for C XDK 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 should be set to the location of the Globalization Support data files. Set the variable as follows: 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 C XDK DLLs and executables. |
You can set the path %path%;%ORACLE_HOME%\bin |
You can test your Windows runtime environment by running any of the utilities described in Table 16-7.
Table 16-7 C/C++ XDK 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 XSLT processor |
|
|
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 16-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 Database Examples media. A README 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 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 16-2 uses bold text to show the path that you need to include.
Example 16-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
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 the following commands at the system prompt:
cd $ORACLE_HOME/xdk/demo/c make
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 16-1.
Figure 16-1 Setting the Include Path in Visual C/C++
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 16-2.
Figure 16-2 Setting the Static Library Path in Visual C/C++
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 16-3.
Figure 16-3 Setting the Names of the Libraries in Visual C/C++ Project
The unified C API is a programming interface that unifies the functionality required by both the XDK and Oracle XML DB. This API is used primarily by XSLT and XML Schema.
As shown in Table 16-4, the unified C API is declared in the xml.h
header file. Table 16-8 summarizes the C XDK APIs. Refer to Oracle XML API Reference for complete documentation.
Table 16-8 Summary of the XDK 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 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 interfaces.
Both XDK 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 obtains xmlctx
, it uses unified DOM calls, all of which take an xmlctx
as the first argument.
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.