C based XML tools in your $ORACLE_HOME

Being triggered by Laurent Schneider’s post “extract xml from the command line“; I completely forgot about the C-based XDK tooling you nowadays can find in your $ORACLE_HOME. You, probably just like me, weren’t even aware, there were some (C-based that is). Most of these are executable’s and not “just” Java tools, although xsql is a shell script that still starts Java. More information can be found here in the “OracleŽ XML Developer’s Kit Programmer’s Guide 11.2

I mean in principle they are not “new”, they were there since 8.1.x, but now they are compiled executables which you can use on the shell prompt and or in scripting and that is, at least for me, easier than doing the same via their $ORACLE_HOME/xdk Java counterparts.

A shortlist:

[oracle@localhost bin]$ pwd
/home/oracle/app/oracle/product/11.2.0/dbhome_2/bin
 
[oracle@localhost bin]$ ls -l x* schema
-rwxr-xr-x 1 oracle oracle 3433339 Jun 23 19:56 schema
-rwxr-xr-x 1 oracle oracle 3582629 Jun 23 19:55 xml
-rwxr-xr-x 1 oracle oracle 4006197 Jun 23 19:56 xmlcg
-rwx------ 1 oracle oracle   49812 Mar 11  2009 xmlwf
-rwxr-xr-x 1 oracle oracle 3485095 Jun 23 19:56 xsl
-rwxr-xr-x 1 oracle oracle     748 Nov 12  2006 xsql
-rwxr-xr-x 1 oracle oracle 3496134 Jun 23 19:56 xvm
 
[oracle@localhost bin]$ file x* schema
xml:    ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), FOR GNU/Linux 2.2.5, dynamically linked (uses shared libs), FOR GNU/Linux 2.2.5, NOT stripped
xmlcg:  ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), FOR GNU/Linux 2.2.5, dynamically linked (uses shared libs), FOR GNU/Linux 2.2.5, NOT stripped
xmlwf:  ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), FOR GNU/Linux 2.2.5, dynamically linked (uses shared libs), FOR GNU/Linux 2.2.5, NOT stripped
xsl:    ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), FOR GNU/Linux 2.2.5, dynamically linked (uses shared libs), FOR GNU/Linux 2.2.5, NOT stripped
xsql:   Bourne shell script text executable
xvm:    ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), FOR GNU/Linux 2.2.5, dynamically linked (uses shared libs), FOR GNU/Linux 2.2.5, NOT stripped
schema: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), FOR GNU/Linux 2.2.5, dynamically linked (uses shared libs), FOR GNU/Linux 2.2.5, NOT stripped

So here a small overview on what they can do…

schema

The “schema” binary is probably the XML Schema Processor and can validate schemas, allowing use of simple and complex XML datatypes.

[oracle@localhost bin]$ schema -h
UNKNOWN switch -h
Usage: schema [flags] <instance> [schema] [working dir]
 
WHERE:
    </instance><instance>    IS the XML instance document TO validate (required)
    [schema]      IS the DEFAULT schema (optional)
    [working dir] IS the working directory FOR processing (optional)
 
Flags:
    -0                Always exit WITH code 0 (success)
    -c                Extra tests TO improve code coverage
    -e <encoding>     Specify DEFAULT INPUT file encoding
    -E </encoding><encoding>     Specify output/DATA/presentation encoding
    -i                IGNORE provided schema file
    -o <num>          Validation options
    -p                Print instance document TO stdout ON success
    -v                SHOW version NUMBER
    -u                forced TO Unicode path
 
[oracle@localhost bin]$ schema -v
Oracle XML Developers Kit 11.2.0.1.0
</num></encoding></instance>

xml

Among others, “xml”, can be used for checks on XML well formedness and creates and parses XML with industry standard DOM and SAX interfaces.

[oracle@localhost bin]$ xml -h
Usage: xml    [switches] [document URI]
  OR   xml -f [switches] [document filespec]
Switches:
    -B <baseuri>      SET the Base uri FOR XSLT processor.
 BaseUri OF http://pqr/xsl.txt resolves pqr.txt TO http://pqr/pqr.txt
    -c                Conformance CHECK ONLY, no validation
    -e <encoding>     Specify DEFAULT INPUT file encoding (-ee TO force)
    -E </encoding><encoding>     Specify output/DATA/presentation encoding
    -f                File - Interpret <document> AS filespec, NOT URI
    -G <xptr exprs>   evaluates XPointer scheme examples give IN a file
    -h                Help - SHOW this usage help (-hh FOR more options)
    -i <n>            NUMBER OF times TO iterate the XSLT processing
    -l <language>     LANGUAGE FOR error reporting
    -o <xsloutfile>   Specify output file OF XSLT processor
    -p                Print document/DTD structures after parse
    -P                Pretty print FROM root element
    -PP               Pretty print FROM root node (DOC); includes XMLDecl
    -PE <encoding>    Specify encoding FOR -P OR -PP output
    -PX               Include XMLDecl IN output always
    -s <STYLE sheet>  STYLE sheet - specifies the XSL STYLE sheet
    -v                Version - SHOW parser version AND exit
    -V <var> <value>  TO test top level VARIABLES IN CXSLT
    -w                Whitespace - preserve ALL whitespace
    -W                Warning - stop parsing after a warning
    -x                Exercise SAX interface FOR parser (prints document)
    -Y                control characters are valid
[oracle@localhost bin]$ xml -cf /tmp/otn_dev_xsd_schema.xml
[oracle@localhost bin]$ xml -cf /tmp/otn_dev_xsd_schema.invalid.xml
IN line 14 OF /tmp/otn_dev_xsd_schema.invalid.xml:
LPX-00225: end-element tag "OWNER" does NOT MATCH start-element tag "ROW"
 
[oracle@localhost bin]$ xml -v
Oracle XML Developers Kit 11.2.0.1.0
</value></var></style></encoding></xsloutfile></language></n></xptr></document></encoding></baseuri>

xmlcf

xmlcg” is a C++ tool to generate C++ classes based on XML input.

[oracle@localhost bin]$ xmlcg -h
Error: UNKNOWN switch
Usage: xmlcg [switches] <document>
    -d <name>          DTD - INPUT IS external DTD (specify output name)
    -o <directory>     Output - specify output directory
    -e <encoding>      Encoding - specify INPUT file encoding
    -h                 Help - SHOW this usage help
    -v                 Version - SHOW Class Generator version#
    -s <name>          Schema - INPUT IS an XML Schema (spec. output name)
 
[oracle@localhost bin]$ xmlcg /tmp/otn_dev_xsd_schema.xml
Generating classes FROM DTD...
[oracle@localhost bin]$ xmlcg  /tmp/otn_dev_xsd_schema.invalid.xml
IN line 14 OF /tmp/otn_dev_xsd_schema.invalid.xml:
LPX-00225: end-element tag "OWNER" does NOT MATCH start-element tag "ROW"
Parse failed, code 225
 
[oracle@localhost bin]$ xmlcg -v
Oracle XML Developers Kit 11.2.0.1.0
</name></encoding></directory></name></document>

xmlwf

The “xmlwf” tool is not described in the XDK manual and just / “only” checks on XML well formedness which can be useful in itself.

[oracle@localhost bin]$ xmlwf -h
usage: xmlwf [-n] [-p] [-r] [-s] [-w] [-x] [-d output-dir] [-e encoding] file ...
 
[oracle@localhost bin]$ xmlwf /tmp/otn_dev_xsd_schema.xml
[oracle@localhost bin]$ xmlwf /tmp/otn_dev_xsd_schema.invalid.xml
/tmp/otn_dev_xsd_schema.invalid.xml:14:17: mismatched tag
 
[oracle@localhost bin]$ xmlwf -v
xmlwf USING expat_2.0.1
sizeof(XML_Char)=1, sizeof(XML_LChar)=1, XML_DTD, XML_CONTEXT_BYTES=1024, XML_NS

xsl

Tool “xsl” is a C XSLT generator and can transform XML into other text-based formats such as HTML.

[oracle@localhost bin]$ xsl -h
Usage: xsl [switches] <stylesheet> <instance>
  OR   xsl -f [switches] [document filespec]
Switches:
    -B <baseuri>      SET the Base uri FOR XSLT processor.
 BaseUri OF http://pqr/xsl.txt resolves pqr.txt TO http://pqr/pqr.txt
    -e <encoding>     Specify DEFAULT INPUT file encoding (-ee TO force)
    -E </encoding><encoding>     Specify output/DATA/presentation encoding
    -f                File - Interpret <document> AS filespec, NOT URI
    -G <xptr exprs>   evaluates XPointer scheme examples give IN a file
    -h                Help - SHOW this usage help (-hh FOR more options)
    -i <n>            NUMBER OF times TO iterate the XSLT processing
    -l <language>     LANGUAGE FOR error reporting
    -o <xsloutfile>   Specify output file OF XSLT processor
    -v                Version - SHOW parser version AND exit
    -V <var> <value>  TO test top level VARIABLES IN CXSLT
    -w                Whitespace - preserve ALL whitespace
    -W                Warning - stop parsing after a warning
</value></var></xsloutfile></language></n></xptr></document></encoding></baseuri></instance></stylesheet>

xsql

Combines XML, SQL, and XSLT in the server to deliver dynamic Web content.

[oracle@localhost bin]$ xsql
Oracle XML Developers Kit 11.2.0.2.0 - Production
XML-25009: Missing arguments ON command line
 
Usage: xsql xsqlFileURI [outFileName] [param1=value1 ... paramN=valueN]

xvm

“xvm” is the C alternative of the XSLT Virtual Machine (XVM) which provides a high-performance XSLT transformation engine that supports compiled stylesheets.

[oracle@localhost bin]$ xvm -h
Usage:
  xvm  switches <xslfile> <xmlfile>
  xvm  switches <xpath> <xmlfile>
 
Switches:
    -c        Compile <xslfile>. The bytecode IS IN '<xmlfile>.xvm'.
    -ct       Compile <xslfile> AND transform <xmlfile>.
    -t        Transform </xmlfile><xmlfile> USING bytecode FROM <xslfile>.
    -xc       Compile <xpath>. The bytecode IS IN 'code.xvm'.
    -xct      Compile AND evaluate </xpath><xpath> WITH <xmlfile>.
    -xt       Evaluate XPath bytecode FROM <xpath> WITH <xmlfile>.
 
Examples:
  xvm  -ct  db.xsl db.xml
  xvm  -t   db.xvm db.xml
  xvm  -xct "doc/emloyee[15]/family"  db.xml
</xmlfile></xpath></xmlfile></xpath></xslfile></xmlfile></xslfile></xmlfile></xslfile></xmlfile></xpath></xmlfile></xslfile>