FAQ Oracle9i XML Developer's Kits


1.0 Overview
2.0 XML Parser and XSLProcessor
   2.1.XML Parser for Java
   2.2.XML Parser for PL/SQL
   2.3.XML Parser for C/C++
3.0 XML Schema Processor
4.0 XML SQL Utility
5.0 XSQL Servlet
6.0 Class Generator
7.0 XML JavaBeans
8.0 Oracle SOAP
9.0 TransX Utility

1.0 Overview

1.1.Can I Create Magnetic Tape Files with Oracle XML?

Question:
Is Oracle XML technology suitable for creating magnetic tape files where the file is just a string of characters like "abcdefg........" in a particular format? Is it is possible to create a stylesheet that will create these kind of files?

Answer:
Yes. Just use to output plain text using:

<xsl:output method="text"/>
  

1.2.Can the parser run on Linux?

Answer:
As long as a 1.1.x or 1.2.x JavaVM for Linux exists in your installation, you can run the Oracle XML Parser for Java there. Otherwise, you can use the C or C++ XML Parser for Linux .

1.3.How Do I Merge XML Documents?

Answer:
This is not possible with the current DOM1 specification. The DOM2 specification may address this. As a workaround, you can use a DOM approach or an XSLT-based approach to accomplish this. If you use DOM, then you'll have to remove the node from one document before you append it into the other document to avoid ownership errors.
Here is an example of the XSL-based approach. Assume your two XML source files are:

demo1.xml
<messages>
<msg>
<key>AAA</key>
<num>01001</num>
</msg>
<msg>
<key>BBB</key>
<num>01011</num>
</msg>
</messages>

demo2.xml
<messages>
<msg>
<key>AAA</key>
<text>This is a Message</text>
</msg>
<msg>
<key>BBB</key>
<text>This is another Message</text>
</msg>
</messages>

Here is a stylesheet that joins demo1.xml to demo2.xml based on matching the <key> values.

demomerge.xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:variable name="doc2" select="document('demo2.xml')"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="msg">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<text><xsl:value-of select="$doc2/messages/msg[key=current()/key]/text"/>
</text>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

If you use the command line oraxsl to test this, you would enter:

$ oraxsl demo1.xml demomerge.xsl

Then, you will get the following merged result:

<messages>
<msg>
<key>AAA</key>
<num>01001</num>
<text>This is a Message</text>
</msg>
<msg>
<key>BBB</key>
<num>01011</num>
<text>This is another Message</text>
</msg></messages>

This is obviously not as efficient for larger files as an equivalent database join between two tables, but this illustrates the technique if you have only XML files to work with.

1.4.How can I use XML with Multiple National Languages?

Question:
My application requires communication with outside entities that may have a totally different language system. If I need to put information in other languages (for instance, Chinese) into XML, do I need to treat and process them differently? For example, do I need to know which encoding they use, or would the parser be able to recognize it? Would there be any problems when dealing with the database?

Answer:
XML inherently supports multiple languages in a single document. Each entity can use a different encoding from the others; that is, you can add a Chinese entity encoded in a Chinese encoding to the rest of the document. You can also treat all portions uniformly, regardless of the language used, by encoding in Unicode. Using the former, you must have an encoding declaration in the XML text declaration.
Oracle XML parsers are designed to be able to handle most external entities and recognize a wide range of encoding, including most widely used ones from all over the world.
The database should support all the languages you are going to use on XML. Chinese character sets such as ZHS16GBK and ZHT16BIG5 are a superset of ASCII so you may be able to use one of them to serve for English and Chinese, but you may want to use Unicode to use more languages.

1.5.How is Oracle's XDK positioning vs. xalan/xerces in OC4J

Question:
How is Oracle going to position its XDK versus the XML Parser/XSLT Stylesheet processor (Xerces/Xalan) components in OC4J? Are they interoperable?

Answer:
Over time, the Xalan/Xerces will be replaced in OC4J by Oracle XML Components via the JAXP 1.1 support which makes XML Parsers and XSLT processors in Java pluggable.

The Oracle SOAP implementation that comes with IAS 1.0.2.2 already has swapped out Xerces with Oracle XML Parser using Oracle XML Parser's JAXP 1.0 support.

1.6.How to get XDK version for Oracle 8.x ?

Answer:
For user using Oracle 8.x version, you can just downlowd 9.x XDK. XDK 9.x doesn't mean only for 9i Database.

Only one issue related to the user with 8.1.6 Database(we don't suggest user to load XDK components to Oracle8i JVM with DB 8.1.5 version or earlier):

You need to use xsu12_816.jar or xsu111_816.jar for loading XSU Components into the Oracle8i JVM.

Please use xdkload or xdkload.bat in the /xdk/bin dir for auto-setup. It take the DB version as one of setup parameter .

1.7.If I Use Versions Prior to Oracle8 i Can I use Oracle XML Tools?

Question:
If I am using an Oracle version earlier than Oracle8i, can I supply XML based applications using Oracle XML tools? If yes, then what are the licensing terms?

Answer:
The Oracle XDKs for Java, C, and C++ can work outside the database, including the XML SQL Utility and XSQL Pages framework. Licensing is the same, including free runtime. See OTN for the latest licenses.

1.8.Is the XML Parser Case-Sensitive?

Question:
The XML file has a tag like: <xn:subjectcode>. In the DTD, it is defined as <xn:subjectCode>. When the file is parsed and validated against the DTD, it returns the error: XML-0148: (Error) Invalid element 'xn:subjectcode' in content of 'xn:Resource',... When I changed the element name to <xn:subjectCode> instead of <xn:subjectcode> it works. Is the parser case-sensitive as far as validation against DTDs go - or is it because, there is a namespace also in the tag definition of the element and when a element is defined along with its namespace, the case-sensitivity comes into effect?

Answer:
XML is inherently case-sensitive, therefore our parsers enforce case sensitivity in order to be compliant. When you run in non-validation mode only well-formedness counts. However <test></Test> would signal an error even in non-validation mode.

1.9.What B2B Standards and Development Tools Does Oracle Support?

Question:
What B2B XML standards (such as ebXML, cxml, and BizTalk) does Oracle support? What tools does Oracle offer to create B2B exchanges?

Answer:
Oracle participates in several B2B standards organizations:
- OBI (Open Buying on the Internet)
- ebXML (Electronic Business XML))
- RosettaNet (E-Commerce for Supply Chain in IT Industry))
- OFX (Open Financial Exchange for Electronic Bill Presentment and Payment))
For B2B exchanges, Oracle provides several alternatives depending on customer needs, such as the following: - Oracle Exchange delivers an out-of-the-box solution for implementing electronic marketplaces)
- Oracle Integration Server (and primarily Message Broker) for in-house implementations)
- Oracle Gateways for exchanges at data level

1.10.What Software Is Needed to Build an XML Application?

Question:
I have a CGI, Perl, and Oracle7 application on Solaris 2.6 and I want to convert it to an XML/XSL, Java, and Oracle application. I know most parts of the technologies,for example, SGML, XML, and Java, but I don't know how to start it in Oracle. What software do I need from Oracle? Specifically,
1. Can I use Apache instead of the Oracle Web server? If so, how?
2. How far can I go with Oracle 7.3?
3. Do I still need an XML parser if all XML was created by my programs?
4. What should be between the Web server and Oracle DB server? XSQL Servlet?
A parser? Java VM? EJB? CORBA? SQLJ? JDBC? Oracle packages such as UTL_HTTP?

Answer:
1. Yes you can. The Apache Web server must now interact with Oracle through JDBC or other means. You can use the XSQL servlet. This is a servlet that can run on any servlet-enabled Web server. This runs on Apache and connects to the Oracle database through a JDBC driver.
2. You can go a long way with Oracle 7.3. The only problem would be that you cannot run any of the Java programs inside the server; that is, you cannot load all the XML tools into the server. But you can connect to the database by downloading the Oracle JDBC utility for Oracle7 and run all the programs as client-side utilities.
3. Whether you still need an XML parser if all XML was created by your programs depends on what you intend to do with the generated XML. If your task is just to generate XML and send it out then you might not need it. But if you wanted to generate an XML DOM tree then you would need the parser. You would also need it if you have incoming XML documents and you want to parse and store them. See the XML SQL utility for some help on this issue.
4. As in the first part of this answer, you would need to have a servlet (or CGI) that interacts with Oracle through OCI or JDBC.

1.11.What is the Best Way to Store XML in a Database?

Question:
What is the best way to store XML in a database? Can I store XML data in an NCLOB? Or is it preferable to store it in a BLOB and manipulate it within the application only?

Answer:
The best way to store XML in Oracle9i is to use the XMLType. Oracle currently allows only CLOB storage natively, but in forthcoming releases Oracle may allow native storage in NCLOBs , BLOB s, etc.

For Oracle9i Release 1 (9.0.1), you can store the XML as:

XMLType - the preferred way. This helps the server to know that the data is XML. You can do XML based querying and indexing.

BLOBs - This helps you store the XML document intact in the same encoding as the original document. The burden is on the user to deal with all the encoding issues.

NCLOBs - Storing XML as NCLOBs will allow you to SQL operations on the data, as well as do Context searches. Context search is supported only if the database charset is a proper super-set or convertible set of the NCHAR, that is, the NCLOB must be convertible to the database char set without loss of data.

1.12.What should DBA do before doing anything with XML in the database?

Question:
I'm looking for suggestions. We have a DBA who tends to be VERY CAREFUL. He's worried that there is a risk involved in installing the Java XDK and its PL/SQL counterpart, and claims that anybody working with XML would want to do it on the application server (which isn't his responsibility). We're on 8.1.7.2, but -- while the XDK is shipped with that version, it requires an extra install step, which he has refused to do, even on our development box.

This has been going on for months now. We're unlikely to move to 9i within the next year. So does anyone have any suggestions on how I might convince him (or, more likely, his management) that we should be allowed to test the tools.

What testing did any of you do before installing the parser, etc. on your development and production instances? Anyone willing to be a reference? Or am I the one who's wrong and we shouldn't be doing anything with XML in the database?

Answer:
The XDK comes pre-installed in 8.1.7.
Your DBA need only GRANT EXECUTE privs on the PL/SQL packages. There should no additional steps.

1.13.What's wrong if I got "ClassNotFoundException"?

Answer:
If you get this kind of error, you need to check if the CLASSPATH is correctly set. Basically you need to set the following jar files into CLASSPATH:

xmlparserv2.jar        : XML Parser V2 for Java
   xschema.jar            : XML Schema Processor for Java    
   xsu12.jar(xsu111.jar)  : XML SQL Utility for Java
   oraclexsql.jar         : XSQL Servlet
   classgen.jar           : XML Class Generator for Java
   classes12.zip(classes111.zip)     : JDBC Driver

back to top

2.0 XML Parser and XSLProcessor

2.1.XML Parser for Java

2.1.1.XML Parser

2.1.1.1.Can I Dynamically Set the Encoding in an XML File?

Answer:
No, you need to include the proper encoding declaration in your document as per the specification. You cannot use setEncoding() to set the encoding for you input document. SetEncoding() is used with oracle.xml.parser.v2.XMLDocument to set the correct encoding for the printing.

2.1.1.2.Can you suggest how to get a print out "macy"using DOM API in java for <name>macy</name>?

Answer:
For DOM , you need to first realize that <name>macy</name> is actually an element named "name" with a child node(Text Node) of value "macy". So you can do the following:

String value = myElement.getFirstChild().getNodeValue();

2.1.1.3.Do you have DTD caching? How do I set the DTD using v2 parser for DTD Cache purpose?

Answer:
Yes. It means if you parse the DTD and set the DTD object to parser, when parser parse multiple XML file, it just take previous DTD object which is setted to validate XML files. DTD caching is optional and it is not enabled automatically.

The method to set the DTD is setDoctype (). Here is an example:

parser = new DOMParser();
parser.setErrorStream(System.out);
parser.showWarnings(true);

FileReader r = new FileReader(arg[0]);
InputSource inSource = new InputSource(r);
inSource.setSystemId(createURL(arg[0]).toString());
parser.parseDTD(inSource.arg[1]);
dtd = (DTD)parser.getDoctype;

r = new FileReader(arg[2]);
InputSource inSource = new InputSource(r);
inSource.setSystemId(createURL(arg[0].toString());
parser.setDoctype(dtd);
parser.setValidateMode(true);
parser.parse(inSource);

doc = (XMLDocument)parser.getDocument();
doc.print(new PrintWriter(System.out));

2.1.1.4.How Do I Extract Data from an XML Document into a String?

Answer:
Here is an example to do that: XMLDocument Your Document;

/* Parse and Make Mods */
:
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
YourDocument.print(pw);
String YourDocInString = sw.toString();

2.1.1.5.How Do I Load External DTDs From a JAR File?

Question:
I would like to put all my DTDs in a JAR file, so that when the XML parser needs a DTD it can get it from the JAR. The current XML parser supports a base URL (setBaseURL()), but that just points to a place where all the DTDs are exposed.

Answer:
The solution involves the following steps: 1. Load the DTD as an InputStream using:

InputStream is =
YourClass.class.getResourceAsStream("/foo/bar/your.dtd");

This will open ./foo/bar/your.dtd in the first relative location on the CLASSPATH that it can be found, including out of your JAR if it's in the CLASSPATH.
2. Parse the DTD with the code:

DOMParser d = new DOMParser();
d.parseDTD(is, "rootelementname");
d.setDoctype(d.getDoctype());

3. Now parse your document with the following code:

d.parse("yourdoc");

2.1.1.6.How Do I Parse XML Stored in NCLOB With UTF-8 Encoding

Question:
I'm having trouble with parsing XML stored in NCLOB column using UTF-8 encoding. Here is what I'm running:
- Windows NT 4.0 Server
- Oracle 8i (8.1.5)
- EEJDeveloper 3.0
- JDK 1.1.8
- Oracle XML Parser v2 (2.0.2.5?)
The following XML sample that I loaded into the database contains two UTF-8 multi-byte characters:


<?xml version="1.0" encoding="UTF-8"?>
<G>
<A>.... multi-byte_W</A>
</G>

The text is supposed to be: G(0xc2, 0x82)otingen, Br(0xc3, 0xbc)ck_W If I am not mistaken, both multibyte characters are valid UTF-8 encodings and they are defined in ISO-8859-1 as:

0xC2 LATIN CAPITAL LETTER A WITH CIRCUMFLEX
0xFC LATIN SMALL LETTER U WITH DIAERESIS

I wrote a Java stored function that uses the default connection object to connect to the database, runs a Select query, gets the OracleResultSet, calls the getCLOB() method and calls the getAsciiStream() method on the CLOB object. Then it executes the following piece of code to get the XML into a DOM object:

DOMParser parser = new DOMParser();
parser.setPreserveWhitespace(true);
parser.parse(istr);
// istr getAsciiStreamXMLDocument xmldoc = parser.getDocument();

Before the stored function can do other tasks, this code throws an exception stating that the above XML contains invalid UTF-8 encoding.
- When I remove the first multibyte character (0xc2, 0x82) from the XML, it parses fine.
- When I do not remove this character, but connect via the JDBC Oracle thin driver (note that now I'm not running inside the RDBMS as stored function anymore) the XML is parsed with no problem and I can do what ever I want with the XML document. I loaded the sample XML into the database using the thin JDBC driver. I tried two database configurations with WE8ISO8859P1/WE8ISO8859P1 and WE8ISO8859P1/UTF8 and both showed the same problem.

Answer:
Yes, the character (0xc2, 0x82) is valid UTF-8. We suspect that the character is distorted when getAsciiStream() is called. Try to use getUnicodeStream() and getBinaryStream() instead of getAsciiStream().

2.1.1.7.How Do I Parse a DTD Object Separately from XML Document?

Question:
How do I parse and get a DTD object separately from parsing my XML document?

Answer:
The parseDTD() method allows you to parse a DTD file separately and get a DTD object. Here is a sample code to do that:

DOMParser domparser = new DOMParser();
domparser.setValidationMode(DTD_validation);
/* parse the DTD file */
domparser.parseDTD(new FileReader(dtdfile));
DTD dtd = domparser.getDocType();

2.1.1.8.How Do I Parse a String?

Answer:
We do not currently have any method that can directly parse an XML document contained within a string. You would need to convert the string into an InputStream or InputSource before parsing. An easy way is to create a ByteArrayInputStream using the bytes in the string.

2.1.1.9.How Do I Use System.out.println() and Special Characters?

Answer:
You can't use System.out.println(). You need to use an output stream which is encoding aware (for example, OutputStreamWriter). You can construct an OutputStreamWriter and use the write(char[], int, int) method to print.

/* Example */
OutputStreamWriter out = new OutputStreamWriter
(System.out, "8859_1");
/* Java enc string for ISO8859-1*/

2.1.1.10.How can I copy and paste a document fragment across different documents?

Answer:
importNode ()[introduced in DOM 2] and adoptNode () [introduced in DOM 3] both can be used to copy and paste a document fragment across different documents.

For adoptNode(), the source node is removed from the original document, while for importNode() the source node is not altered or removed from the original document.

Here is an example:

Document doc1 = new XMLDocument();
   Element element1 = doc1.createElement("foo");
   Document doc2 = new XMLDocument();
   Element element2 = doc2.createElement("bar");
   element1.appendChild(element2);

Since the owner document of element1 is doc1 while that of element2 is doc2 and appendChild() only works within a single DOM tree, you will get WRONG_DOCUMENT_ERR.

Solution 1: Using adoptNode from DOM Level 3

Document doc1 = new XMLDocument();
   Element element1 = doc1.createElement("foo");
   Document doc2 = new XMLDocument();
   Element element2 = doc2.createElement("bar");
   element2 = doc1.adoptNode(element2);
   element1.appendChild(element2);

Solution 2: Using importNode from DOM Level 2

Document doc1 = new XMLDocument();
   Element element1 = doc1.createElement("foo");
   Document doc2 = new XMLDocument();
   Element element2 = doc2.createElement("bar");
   element2 = doc1.importNode(element2);
   element1.appendChild(element2);

2.1.1.11.How can make the XML Parser ignore the parsing the <!DOCTYPE> tag?

Answer:
There are two ways to do:
1. put standalone="yes" to <?xml ...?>declaration. 2. Starting XDK for Java 9.0.2D, the customer can use the function

xmlparser.setAttribute(XMLParser.STANDALONE, Boolean.TRUE)

to treat the input file as if it had standalone="yes" in the XML declaration.

2.1.1.12.How do I create a DocType Node?

Question:
For example, emp.dtd has the following DTD:


<!ELEMENT employee (Name, Dept, Title)>
<!ELEMENT Name (#PCDATA)>
<!ELEMENT Dept (#PCDATA)>
<!ELEMENT Title (#PCDATA)>

How do I create a DocType Node?

Answer:
You can use the following code to create a DOCTYPE node:

parser.parseDTD(new FileInputStream(emp.dtd), "employee");
doc = parser.getDocument();
/* doc has the dtd as its child or dtd = parser.getDoctype();*/

2.1.1.13.How do I use the selectNodes() method in XMLNode class?

Answer:
The selectNodes() method is used in XMLElement and XMLDocument nodes. This method is used to extract contents from the tree/subtree based on the select patterns allowed by XSL .

The optional second parameter of selectNodes , is used to resolve Namespace prefixes (return the expanded namespace URL given a prefix).

XMLElement implements NSResolver , so it can be sent as the second parameter. XMLElement resolves the prefixes based on the input document. You can implement the NSResolver interface, if you need to override the namespace definitions.

The following sample code uses selectNodes:

public class SelectNodesTest  {
    public static void main(String[] args) throws Exception {
    String pattern = "/family/member/text()";
    String file    = args[0];
    
    if (args.length == 2)
      pattern = args[1];
    
    DOMParser dp = new DOMParser();
    
    dp.parse(createURL(file));  // Include createURL from DOMSample
    XMLDocument xd = dp.getDocument();
    XMLElement e = (XMLElement) xd.getDocumentElement();
    NodeList nl = e.selectNodes(pattern, e);
    for (int i = 0; i < nl.getLength(); i++) {
       System.out.println(nl.item(i).getNodeValue());
        }
      }
    }

2.1.1.14.How does the XML Parser for Java Recognize External DTDs?

Question:
How does the XML Parser for Java version 2 recognize external DTDs when running from the server? The Java code has been loaded with loadjava and runs in the Oracle9i server process. My XML file has an external DTD reference.
1. Is there a generic way, as there is with the SAX parser, to redirect it to a stream or string or something if my DTD is in the database?
2. Is there a generic way to redirect the DTD, as there is with the SAX parser, with resolveEntity()?

Answer:
1. We only have the setBaseURL() method at this time.
2. You can achieve your desired result using the following:
a. Parse your External DTD using a DOM parser's parseDTD() method.
b. Call getDoctype() to get an instance of oracle.xml.parser.v2.DTD.
c. On the document where you want to set your DTD programmatically, use the setDoctype(yourDTD). We use this technique to read a DTD out of our product's JAR file.

2.1.1.15.Is XML Parser v2 thread safe?

Answer:
1/ If you instanciate a DOMParser in a singleton class, you can't have multiple threads use this single instance to produce XMLDocument objects.

Currently we don't support multiple thread safe for DOM parser.

2/ Once I have a XMLDocument object, you can have multiple threads use it simultaneously only when reading is involved. If Write is involve you have to do the synchronization.

3/ You can have several threads call XMLDocument.getDocumentElement() on the sameXMLDocument object, Since it is read.But if WRITE is doing, synchronization must be taken.

4/ You have to lock the Node object, before cloning node in multi-thread conditon.

2.1.1.16.Why are Only the Child Nodes are Inserted?

Question:
When appending a document fragment to a node, only the child nodes of the document fragment (but not the document fragment itself) are inserted. Wouldn't the parser check the owner document of these child nodes?

Answer:
A document fragment should not be bound to a root node, since, by definition, a fragment could very well be just a list of nodes. The root node, if any, should be considered a single child. That is, you could for example take all the lines of an Invoice document, and add them into a ProviderOrder document, without taking the invoice itself. How do we create a document fragment without root? As the XSLT processor does, so that we can append it to other documents.

2.1.1.17.Why my parser doesn't find the DTD file?

Answer:
The DTD file defined in the <!DOCTYPE> declaration must relative to the location of the input XML Document. Otherwise, you'll need to use the setBaseURL (url) functions to set the base URL to resolve the relative address of the DTD if the input is coming from an Input Stream.

2.1.1.18.Why the parser can't find the DTD?

Answer:
The DTD file defined in the <!DOCTYPE> declaration must be relative to the location of the input XML document. Otherwise, you'll need to use the setBaseURL(url) functions to set the base URL to resolve the relative address of the DTD if the input is coming from InputStream.

back to top

2.1.2.XSL Processor

2.1.2.1.Why I can't get all the text content with in a node?

Question:
I am trying to use <xsl:value-of select="/technology/doc//text()"/> for following document: ... <doc><child>first child</child> <child>second child</child></doc> What I dot is only "first child" why?

Answer:
If select in xsl:value-of return a node-set xsl:value-of will only return text value of first node. If select in xsl:value-of return a node then xsl:value-of will return concatent of all the text value within this node, which inlcude its child node. So using <xsl:value-of select="/technology/doc//text()" /> will return first text node value of /doc. <xsl:value-of select="/technology/doc"/> will return all the text nodes' value in /doc.

2.1.2.2.Why I can't get all the text content with in a node?

Answer:
If select in xsl:value-of return a node-set xsl:value-of will only return text value of first node. If select in xsl:value-of return a node then xsl:value-of will return concatent of all the text value within this node, which inlcude its child node.

So using

<xsl:value-of select="/technology/doc//text()" />

will return first text node value of /doc.

<xsl:value-of select="/technology/doc"/>

will return all the text nodes' value in /doc.

2.1.2.3.Why XSL Processor can't find the external document while using document() in XSL?

Question:
The following XSL template works fine with the command oraxsl , like:


   oraxsl sample.xml detail.xsl
   ...
   <xsl:template match="BusinessServiceRequester/Verb">
   <xsl:value-of select="document('traduction.xml')//FR/VB" />
   <xsl:value-of select="." />
   </xsl:template>
   ...

and when I try to apply the xsl from a java program with:

...
XSLProcessor processor = new XSLProcessor();

// Process XSL
DocumentFragment result = processor.processXSL(xsl, xml);

I get:

oracle.xml.parser.v2.XSLException: XSL-1021: Error parsing external document: 'no protocol: traduction.xml'.
at oracle.xml.parser.v2.XSLStylesheet.error(XSLStylesheet.java:1607)
...

It does not accept an external document ?!

Answer:
This simply means that in your Java program you have not properly set the BaseURL of the XSL stylesheet, so it cannot properly resolve relative references to files "in the same directory". Using a URL to construct your XSLStylesheet object is the easiest way to get the base URL set correctly.

back to top

2.2.XML Parser for PL/SQL

2.2.1.How do I append a text node to a DOMElement using PL/SQL parser?

Answer:
Use the createTextNode() method to create a new text node . Then convert the DOMElement to a DOMNode using makeNode(). Now, you can use appendChild () to append the text node to the DOMElement.

2.2.2.How do I generate a document object from a file?

Answer:

Check out the following example:

inpPath VARCHAR2;
inpFile VARCHAR2;
p xmlparser.parser;
doc xmldom.DOMDocument;

-- initialize a new  parser object;
p := xmlparser.newParser;
-- parse the file
xmlparser.parse(p, inpPath || inpFile);
-- generate a document object
doc := xmlparser.getDocument(p);

2.2.3.How do I get the DOCTYPE tag into the XMLDocument after its parsed?

Answer:
You need to do some preprocessing to the file( getDoctype ()), and then put it through the DOMParser again( setDoctype ()), which will produce a valid, well-formed XMLDocument with the DOCTYPE tag contained within.

Here is an example:

-- new parser
    p := xmlparser.newParser;

    -- parse dtd file
    xmlparser.parseDTD(p, dir || '/' || dtdfile, root);
    dt := xmlparser.getDoctype(p);

    -- parse input file
    xmlparser.setValidationMode(p, true);
    xmlparser.setDoctype(p, dt);
    xmlparser.parse(p, dir || '/' || inpfile);

    -- get document
    doc := xmlparser.getDocument(p);

   ------------------------------------------------------
   -- Set DOCTYPE Tag
   ------------------------------------------------------
   xmldom.setDoctype(doc,'family','/tmp/family.dtd','');

   xmldom.writeToFile(doc, dir || '/' || 'familyout.txt');

    Notes:
      dtdfile - varchar2 parameter for DTD File.
      dir - varchar2 parameter directory information
      inpfile - input xml file.

2.2.4.How do I write the XML data back using a special character sets?

Answer:
You can specified the character sets for writing to a file or a buffer. Writing to a CLOB will be using the default character set for the database that you are writing to. Here are the methods to use:

procedure writeToFile(doc DOMDocument, fileName VARCHAR2, charset VARCHAR2);
  procedure writeToBuffer(doc DOMDocument, buffer IN OUT VARCHAR2, charset VARCHAR2);
  procedure writeToClob(doc DOMDocument, cl IN OUT CLOB, charset VARCHAR2);

2.2.5.How to use PL/SQL XML Parser package under AIX platform?

Question:
I have to use a XML parser with PL/SQL on a AIX System, but on the oracle donwload site there is no one version for AIX. Could I use one of the other Unix Versions like the Solaris one?

Answer:
Basically you can use our PL/SQL XML parser because it is based on Java. But there a known problem for JIT (Just In Time Compiler) under AIX .

Please turn of the JIT and run the program by:

1/ set enviroment variable

setenv JAVA_COMPILER NONE

or 2/ run java with -D option, like:

java -Djava.compiler=NONE <your program>

2.2.6.Is there a PL/SQL parser that is based on C?

Answer:
No. It is based on Java. But C version will soon be released.

2.2.7.What are the memory requirements for using the PL/SQL Parser?

Answer:
While the memory use is directly dependent on the document size, it should also be realized that the PL/SQL parser uses the Java parser and thus the Oracle JServer is being run. JServer typically requires 40-60MB depending on its configuration.

2.2.8.What is the easiest way to get the value of a DOM element?

Question:
I have problems when I get a value from XML. I work with XMLDOM and PLSQL (ORACLE 8i).
This is my code (it works ok):

begin

x_parser := xmlparser(x_parser,v_xml);
xmlparser.parserbuffer(x_parser,v_xml);
x_doc := xmlparser.getdocument(x_parser);
x_node_list := xmldom.getElementsbytagname(x_doc,'*');
x_node := xmldom.item(x_node_list,2); -- look this
x_node := xmldom.getfirstchild(x_node);
v_value := xmldom.getNodeValue(x_node);

end

I don't want to use index to get a value I must use node's name. In my code I use index 2 but I want to use a tag 'NAME' (node's name).
and my xml is


<?xml version='1.0'?>
<IN>
<EMP>
<NAME>TONY</NAME>
<SEX>M</SEX>
<DATE>01/12/2001</DATE>
</EMP>
</IN>

Answer:
You can use xpath to get the value of your element. Here is the example. The try.xml just be your input XML file:

PL/SQL:
declare
parser xmlparser.parser;
doc xmldom.DOMDocument;
node xmldom.DOMNode;
elem xmldom.DOMElement;
value varchar2(50);
begin
parser := xmlparser.newparser;

xmlparser.parse(parser,

'/private/jiwang/info/xdk_info/plsqlj/ex1005_valueof/try.
xml');
doc := xmlparser.getdocument(parser);

elem := xmldom.getDocumentElement(doc);
node := xmldom.makeNode(elem);

value := xslprocessor.valueof(node,'/IN/EMP/NAME/text()');
dbms_output.put_line(value);

end;
/

You will get: "TONY" as result.

2.2.9.Why I get error messages like "identifier 'XMLPARSER.PARSER'

Answer:

Two steps to solve the problem:
    
     Step 1: connect to database as sysdba and try command:

              desc xmlparser

      If you can see the package, you don't need to load it again, but:

              grant execute on xmldom to <username>;
              grant execute on xmlparser to <username>;
              grant execute on xslprocessor to <username>;

  
     Step 2: If you can't see the package then you need to load PL/SQL
       package by using:

       1) Download the latest release of the Oracle XML Parser for PL/SQL
          from http://technet.oracle.com/tech/xml

       2) Extract the .zip or the .tar.gz file into a convenient directory

       3) run shell script(xdkload) or batch file(xdkload.bat) in the /bin
          directory

2.2.10.Why I got "Error occurred while parsing: Start of root element expected"?

Question:
When I try to parse XML file using PL/SQL XML Parser, I got following error Messages:

ERROR at line 1:
    ORA-20100: Error occurred while parsing: Start of root element expected.
    ORA-06512: at "XDKDEMO.XMLPARSER", line 22
    ORA-06512: at "XDKDEMO.XMLPARSER", line 86
    ORA-06512: at "XDKDEMO.MAKEGLOSSARY", line 53
    ORA-06512: at line 1

Would you tell me why?

Answer:
This error happens when your XML file is not well-formed. If you XML file is well-formed , please check the function used in PL/SQL Programming.

If you try to use parserBuffer to parse a file the you will got this error.

For Example:

xmlparser.parseBuffer(p, dir ||'/'||'try.xml'); -- Error!

back to top

2.3.XML Parser for C/C++

2.3.1.Do I need Oracle 8i/9i to run the XML Parser for C v2?

Answer:
No.

2.3.2.How do I parse a string using xmlpaser for C?

Answer:
You can use xmlparsebuf() to parse a string.

2.3.3.Why I got "Failed to initialize XML parser, error 201"?

Answer:
If you got "Failed to initialize XML parser, error 201", you need to check if the environment variable ORA_NLS33 is set to point to the location of the NLS data files. On Unix systems, this is usually $ORACLE_HOME/common/nls/admin/data. On Windows NT, this is usually $ORACLE_HOME/nlsrtl/admin/nlsdata. Starting with version 9.0.1, C and C++ XDK releases that are downloaded from OTN contain an nlsdata/ subdirectory. You must set the environment variable ORA_NLS33 to the absolute path of the nlsdata/ subdirectory if you don't have an Oracle installation.

2.3.4.Why a new parser can't be created the second time in an application to parse another file?

Answer:
You can create new parser only if you have enough memory.

After you do the xmlinit() and parse the data you will got all the memory allocated for xml processing and the parsed data.

So if you don't need to use the data later or will use new parser, you need to do xmlclean() or xmlterm() after that which xmlterm will especially return all the memory back to the system.

back to top

3.0 XML Schema Processor

3.1.What features does Oracle XML Schema for C supported?

Answer:
- Simple and complex types;
- Build on XML Parser for C v2;
- Support W3C XML Schema Working Drafts.

3.2.What is the example calling sequence of XML Schema Processor for C++?

Answer:
1/ XMLSchema.initialize(): initializes the process
2/ Parse XML documents as input to Schema Processor
3/ XMLSchema.validate(): validate the parsed XML Documents
4/ XMLSchema.terminate(): end the process

back to top

4.0 XML SQL Utility

4.1.: What database schema structure should I use to store this xml with XSU?

Question:
I have the following XML in my customer.xml file:


<ROWSET>
<ROW num="1">
  <CUSTOMER>
   <CUSTOMERID>1044</CUSTOMERID>
   <FIRSTNAME>Paul</FIRSTNAME>
   <LASTNAME>Astoria</LASTNAME>
   <HOMEADDRESS>
    <STREET>123 Cherry Lane</STREET>
    <CITY>SF</CITY>
    <STATE>CA</STATE>
    <ZIP>94132</ZIP>
   </HOMEADDRESS>
  </CUSTOMER>
</ROW>
</ROWSET>

What database schema structure should I use to store this xml with XSU?

Answer:
Since your example is more than one level deep (i.e. has a nested structure), you should use an object-relational schema. The XML above will canonically map to such a schema. An appropriate database schema would be the following:

create type address_type as object
(
street varchar2(40),
city varchar2(20),
state varchar2(10),
zip varchar2(10)
);
/
create type customer_type as object
(
customerid number(10),
firstname varchar2(20),
lastname varchar2(20),
homeaddress address_type
);
/
create table customer_tab ( customer customer_type);

In the case you wanted to load customer.xml via the XSU into a relational schema, you could still do it by creating objects in views on top of your relational schema.

For example, you would have a relational table which would contain all the information:

create table cust_tab
( customerid number(10),
   firstname varchar2(20),
   lastname varchar2(20),
   state varchar2(40),
   city varchar2(20),
   state varchar2(20),
   zip varchar2(20)
);

Then you would create a customer view which contains a customer object on top of it, as in:

create view customer_view as
select customer_type(customerid, firstname, lastname,
address_type(state,street,city,zip))
from cust_tab;

Finally, you could flatten your XML using XSLT and then insert it directly into your relational schema. This is the least recommended option.

4.2.Can XML- SQL Utility store XML data across tables?

Answer:
Currently XML-SQL Utility (XSU) can only store to a single table. It maps a canonical representation of an XML document into any table/view. But of course there is a way to store XML with the XSU across table. One can do this using XSLT to transform any document into multiple documents and insert them separately. Another way is to define views over multiple tables (object views if needed) and then do the inserts... into the view. If the view is inherently non-updatable (because of complex joins,...), then one can use INSTEAD-OF triggers over the views to do the inserts.

4.3.Can XML- SQL Utility store XML data across tables?

Question:
Can you explain how to map table columns to XML attributes using XSU?

Answer:
From XML SQL Utility release 2.1.0 you can map a particular column or a group of columns to an XML attribute instead of an XML element. To achieve this, you have to create an alias for the column name, and prepend the at sign (@) to the name of this alias. For example :

* Create a file called select.sql with the following content :

SELECT empno "@EMPNO", ename, job, hiredate
   FROM emp
   ORDER BY empno

* Call the XML SQL Utility :

java OracleXML getXML -user "scott/tiger" \
           -conn "jdbc:oracle:thin:@myhost:1521:ORCL" \
           -fileName "select.sql"

* As a result, the XML document will look like :

<?xml version = '1.0'?>
     <ROWSET>
        <ROW num="1" EMPNO="7369">
           <ENAME>SMITH</ENAME>
           <JOB>CLERK</JOB>
           <HIREDATE>12/17/1980 0:0:0</HIREDATE>
        </ROW>
        <ROW num="2" EMPNO="7499">
           <ENAME>ALLEN</ENAME>
           <JOB>SALESMAN</JOB>
           <HIREDATE>2/20/1981 0:0:0</HIREDATE>
        </ROW>
     </ROWSET>

Note: All attributes must appear before any non-attribute.Since the XML document is created in a streamed manner, the query :

SELECT ename, empno "@EMPNO", ...

would not generate the expected result.

It is currently not possible to load XML data stored in attributes. You will still need to use an XSLT transformation to change the attributes into elements.

XML SQL Utility assumes canonical mapping from XML to a database schema.

4.4.Can You Provide a Thin Driver Connect String Example for XSU?

Question:
I am using the XML SQL Utility command line front end, and I am passing a connect string but I get a TNS error back. Can you provide examples of a thin driver connect string and an OCI8 driver connect string?

Answer:
An example of an JDBC thin driver connect string is:

jdbc:oracle:thin:<user>/<password>@<hostname>:<port number>:<DB SID>;

furthermore, the database must have an active TCP/IP listener. A valid OCI8 connect string would be:

jdbc:oracle:oci8:<user>/<password>@<hostname>

4.5.Does XML SQL Utility commit after it's done inserting/deleting/updating?

Question:
Given a DTD, will XML SQL Utility generate the database schema?

Answer:
No. Due to a number of shortcomings of the DTD, this functionality is not available. Once the W3C XML Schema recommendation is finalized this functionality will become feasible.

4.6.Does XML SQL Utility commit after it's done inserting/deleting/updating? What happens if an error occurs?

Answer:
By default the XML SQL Utility executes a number of insert (or del or update) statements at a time. The number of statements batch together and executed at the same time can be overridden using the "setBatchSize" feature. By default the XML SQL Utility does no explicit commits. If the autocommit is on (default for the JDBC connection) then after each batch of statement executions a commit happens. The user can override this by turning autocommit off and then specifying after how many statement executions should a commit occur which can be done using the "setCommitBatch" feature.

Finally, what happens if an error occurs... Well, the XSU rolls back to either the state the target table was before the particular call to the XSU, or the state right after the last commit made during the current call to the XSU.

4.7.How Do I Load a Large XML Document Into the Database?

Question:
I have a large (27 MB) data-centric XML document. I could not load it into the database when it was split into relational tables with XML SQL Utility, because the DOM parser failed (memory leak) during the XSLT processor execution. Do you have a workaround for this problem? Should I use SAX Parser? How do I use the XSLT processor and Sax Parser?

Answer:
1/ If this is a one time load, or if the XML document you get always has the same tags, then you might consider using the SQL*Loader (direct path). All you have to do is compose a loader control file (see the Oracle9i Utilities manual, Chapter 3, for examples). You can use the enclosed by option to describe the fields. For example, in the files list you enter something like the following:

(empno    number(10)    enclosed by "<empno>" and "</empno>",...)

Except for the data parsing which has to be done the same regardless of what you are using, the actual loading into the database will be fastest with SQL*Loader (as the direct path writes data straight to data blocks, bypassing the layers in between).

2/If the document is 27 MB because it is a very large number of repeating sub-documents, then you can use the sample code that comes in Chapter 14 of the book "Building Oracle XML Applications" by Steve Muench (O'Reilly) to load XML of any size into any number of tables. In Chapter 14, "Advanced XML Loading Techniques", the example builds an XML Loader utility that does what you are looking for.

4.8.I would like to use XML SQL Utility to load XML where some of the data is stored in attributes; yet, XML SQL Utility seems to ignore the XML attributes. What can I do?

Answer:
Unfortunately, for now you will have to use XSLT to transform your XML document (that is, change your attribute s into elements). XML SQL Utility does assume canonical mapping from XML to a database schema. This takes away a bit from the flexibility, forcing you to sometimes resort to XSLT, but at the same time, in the common case, it does not burden you with having to specify a mapping.

4.9.Is XML-SQL Utility is Case Sensitive?

Question:
I am trying to insert the following XML document (dual.xml):


<ROWSET>
   <row>
      <DUMMY>X</DUMMY>
   </row>
</ROWSET>

Into the table "dual" using the command line front end of the XSU, like in:

java OracleXML putxml -filename dual.xml dual

and I get the following error:

oracle.xml.sql.OracleXMLSQLException: No rows to modify -- the row enclosing
tag missing.  Specify the correct row enclosing tag.

Answer:
By default the XML SQL Utility is case sensitive, so it looks for the record separator tag which by default is "ROW"; yet, all it can find is "row". So if you insert following XML document:

<ROWSET>
   <row>
      <DUMMY>X</DUMMY>
   </row>
</ROWSET>

You will got error like this:

oracle.xml.sql.OracleXMLSQLException: No rows to modify -- the row enclosing
tag missing.  Specify the correct row enclosing tag.

Another related common mistake is to case mismatch one of the element tags. For example if in dual.xml the tag "DUMMY" was actually "dummy" than the XML SQL Utility would also raise an error complaining that if couldn't find a matching column in the table "dual". So user has two options -- use the correct case or use the "ignoreCase" feature.

4.10.Why I got "ORA-29547: Java system class not available: oracle/aurora/rdbms/Compiler"?

Question:
The README file said to use the loadjava to upload xmlparserv2.jar and plsql.jar in order. When I tried to load xmlparserv2.jar using the following command

loadjava -user test/test -r -v xmlparserv2.jar

to upload the jar file into an 8i database. After much of the uploading, I got the following error messages:

identical: oracle/xml/parser/v2/XMLConstants is unchanged from previously loaded file
identical: org/xml/sax/Locator is unchanged from previously loaded file
loading : META-INF/MANIFEST.MF
creating : META-INF/MANIFEST.MF
Error while creating resource META-INF/MANIFEST.MF
ORA-29547: Java system class not available: oracle/aurora/rdbms/Compiler

Answer:
The JServer option is not properly installed if you're getting errors like this during loadjava. You need to run INITJVM.SQL and INITDBJ.SQL to get the JavaVM properly installed. Usually these are in the ./javavm subdirectory of your Oracle Home.

4.11.Why I got " java.text.ParseException: Unparseable date: "?

Question:
Whilst using the DBMS_XMLSave.updateXML procedure I am having problems parsing a date which is the format dd/mm/yy
I have tried to use the following procedure to set the date format :

DBMS_XMLSave.setDateFormat(updCtx,'DD/MM/YY');

Unfortunately it is not working, as the parser still does not recognise the date format, it seems to want the time element.
please may somebody advise on some possible solutions

Answer:
The date formats must match java date formats not Oracle date formats. For a list of valid date formats please check http://java.sun.com/products/jdk/1.1/docs/api/java.text.SimpleDateFormat.html

4.12.Would you tell us something about the performace of XSU?

Answer:
About XSU performance : 1/ For each specific query, there is one time overhead to do the data mapping between XML Doc and DB Schema, then your insertion and retrieval operations will not be much of the difference than normal operations through JDBC.

2/ For Oracle 9.0.1 Database there is one package implement inside server: DBMS_XMLGEN which will also overcome the overhead of Java-based packages and has better performance.

back to top

5.0 XSQL Servlet

5.1.Can the XSQL Servlet connect to any DB that has JDBC support?

Answer:
The Oracle XSQL Page processor has been designed to exploit the maximum set of features against the Oracle JDBC drivers, but gracefully degrade to work against any database with a reasonable JDBC driver. While numerous users have reported successfully using XSQL Pages with many other JDBC drivers, the ones that we have tested in-house are: Oracle8i 8.1.5 Driver for JDBC 1.x Oracle8i 8.1.6 Driver for JDBC 1.x Oracle8i Lite 4.0 Driver for JDBC 1.x Oracle8i 8.1.6 Driver for JDBC 2.0

5.2.Can we perform DML operations using XSQL servlet?

Question:
We can select from tables andpresent it in XML or HTML format. Can we do an Insert or Update using the servlet?

Answer:
Yes.This is supported using the <xsql:dml> tag or using the <xsql:insert-request> tag.

5.3.Can you set up XSQL pages to use connections taken from a connection pool?

Question:
Can you set up XSQL pages to use connections taken from a connection pool? For example, if you are running XSQL servlet in a Weblogic web server, how would the connection definition have to be set up to take a connection from the existing pool?

Answer:
XSQL implements it's own connection pooling so in general you don't have to use another connection pool , but if providing the JDBC connection string of appropriate format is not enough to use the WebLogic pool, then you can create your own custom connection manager for XSQL (a lot more work than the JDBC connection string, of course) by implementing the interfaces XSQLConnectionManagerFactory and XSQLConnectionManager.

5.4.How to convert XML to Excel?

Question:
I understand that their is a way to convert xml files generated by xsql to excel with help of xsl.. Any idea about this??

Answer:
Here's an example:

excel.xsql

<?xml version="1.0"?>
<?xml-stylesheet href="excel.xsl" type="text/xsl"?>
<xsql:query connection="demo" xmlns:xsql="urn:oracle-xsql">  
  select * from emp order by sal desc
</xsql:query>

excel.xsl

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">  
<xsl:output method="html" media-type="application/vnd.ms-excel"/>  <xsl:template match="/technology/">
   <html>
     <table>          
        <tr>
          <th>EMPNO</th>
          <th>ENAME</th>
          <th>SAL</th>
        </tr>      
        <xsl:for-each select="ROWSET/ROW">
        <tr>
           <td><xsl:value-of select="EMPNO"/></td>              
           <td><xsl:value-of select="ENAME"/></td>
           <td><xsl:value-of select="SAL"/></td>
        </tr>
      </xsl:for-each>
     </table>
   </html>
  </xsl:template>
</xsl:stylesheet>

5.5.How can I keep parameters for further use?

Question:
Using XSQL Servlet, I receive parameters, and I need to keep them safe for further use, in a few pages to be reached later. My idea is to keep them as hidden fields or the equivalent. I want to build an original XML document that looks like the following:


<root xmlns:xsql blah blah blah>
  <toBeTurnedAsForm action="doThis" method="POST">
    <aHiddenField name="secret" value="{@IGotYou}"/> ....
  </toBeTurnedAsForm>
</root>

As the <aHiddenField>tag does not belong to the XSQL name space, the parsing of the variable is not done. Is there a simple way to do it? I would not like to have a select '{@IGotYou}' from dual to make.

Answer:
Use <xsql:include-param name="IGotYou"/> to include the value of a parameter in your datapage, then your XSL stylesheet can transform the: <IGotYou>ValueOfIGotYou</IGotYou> into wherever it needs to go in your HTML page.

5.6.How can I use multiple queries in an .xsql File?

Question:
Page Parameters:I have two queries in an .xsql file.


<xsql:query>select col1,col2 from table1</xsql:query>
<xsql:query>select col3,col4 from table2
    where col3 = {@col1} => the value of col1 in the previous query
</xsql:query>

How can I use, in the second query, the value of a select list item of the first query?

Answer:
You do this with page parameters.

<page xmlns:xsql="urn:oracle-xsql" connection="demo">
<!-- Value of page param "xxx" will be first column of first row -->
<xsql:set-page-param name="xxx">
select one from table1 where ...
</xsl:set-param-param>
<xsql:query>
select col3,col4 from table2.
where col3 = {@xxx}
</xsql:query>
</page>

5.7.How to deploy Oracle XSQL Pages to OC4J ?

Answer:
Follow these steps to install Oracle XSQL Pages Publishing Framework on the Oracle Containers for J2EE (OC4J):

1.Download the latest XDK for Java Release from OTN from

/tech/xml/xdk_java

The latest production release is XDK 9.0.1, which includes Oracle XSQL Pages. Let's assume that you download the tar.gz version, who file name will be xdk_java_9_0_1_0_0.tar.gz):

2.Create a staging directory in which to prepare the EAR file for XSQL, for example /xsqlj2ee):

3.Under /xsqlj2ee create the following additional subdirectories:

/xsqlj2ee/META-INF
        /xsqlj2ee/WEB-INF
        /xsqlj2ee/WEB-INF/lib
        /xsqlj2ee/WEB-INF/classes

4.Create the file /xsqlj2ee/META-INF/application.xml with the following contents:

<!DOCTYPE application PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN' 'http://java.sun.com/j2ee/dtds/application_1_2.dtd'>
  <application>
     <display-name>Oracle XSQL Servlet</display-name>
     <description>Oracle XSQL Servlet</description>
     <module>
        <web>
          <web-uri>xsql.war</web-uri>
          <context-root>AppRoot</context-root>
        </web>
     </module>
  </application>

5.Create the file /xsqlj2ee/WEB-INF/web.xml with the following contents:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">
<web-app>
    <servlet>
      <servlet-name>oracle-xsql-servlet</servlet-name>
      <servlet-class>oracle.xml.xsql.XSQLServlet</servlet-class>
    </servlet>
    <servlet-mapping>
      <servlet-name>oracle-xsql-servlet</servlet-name>
      <url-pattern> *.xsql </url-pattern>
    </servlet-mapping>
  </web-app>

6.Create a root directory in which to extract the contents of the XDK distribution, for example /xdk901):

7.Change directory to /xdk901 and extract the XDK 9.0.1 archive using tar xvfz.):

8.Copy the following jar files to /xsqlj2ee/WEB-INF/lib:

/xdk901/lib/oraclexsql.jar
    /xdk901/lib/xsqlserializers.jar
    /xdk901/lib/xmlparserv2.jar
    /xdk901/lib/xsu12.jar

9.Copy /xdk901/xdk/admin/XSQLConfig.xml to /xsqlj2ee/WEB-INF/classes):

10.Move or "deep copy" the contents of /xdk901/xdk/demo/java/xsql to the directory /xsqlj2ee/demo):

11.Change directory to /xsqlj2ee):

12.Create the xsql.war file with the command:

$ jar cvf xsql.war WEB-INF demo

13.Create the xsqlj2ee.ear file with the command:

$ jar cvf xsqlj2ee.ear META-INF xsql.war

14.Make sure your OC4J Server is running. Let's assume it's running on localhost.):

15.Change directory to your OC4J server root, for example /j2ee/home):

16.Deploy the xsqlj2ee.ear application to the server with the command (all on one command line):

java -jar admin.jar ormi://localhost admin welcome
   -deploy -deploymentName xsqlj2ee -file /xsqlj2ee/xsqlj2ee.ear

17.Edit the /j2ee/home/config/default-web-app.xml file to add the line:

<web-app application="xsqlj2ee" name="xsql" root="/technology/xsql" />

18.Finally, browse the URL http://yoursever:yourport/xsql/demo/index.html):

19.And don't forget to read the rewritten chapter in the Oracle9i online document about Oracle XSQL Pages

5.8.How to group duplicate value suppression in XSQL?

Question:
In SQL*Plus, duplicate values can be suppressed with the "break on .." command. Is there any equivalent in XSQL??

Answer:
There are a couple of ways to approach this.
1. You can do the grouping in your SQL statement, by selecting the distinct values in an outer SELECT and the nested details in an inner CURSOR() expression. Or alternatively,...
2. You can do the grouping in your XSLT stylesheet Steve Muench's Book "Building Oracle XML Applications" book dedicates a section in Chapter 9 to techniques for doing this kind of grouping in XSLT to present one- or multi-level break reports like you're thinking of from SQL*Plus or Oracle Reports.
The technique that I present in steve's book was coined the (blush...) "Muenchian Method" for doing grouping in XSLT. If you don't have the book, you can go to http://www.google.com and type in "Muenchian Method" and get some links that explain the technique as well.

5.9.How to include XML stored in CLOB into XSQL output?

Question:
I want to include and XML stored into CLOB in my XSQL output. This is working fine except that in the XML extracted from the CLOB all the opening tags are replaced by &lt; . How to avoid this?

Answer:
Starting with XSQL 9.0.2A, you can do:

<yourpage connection="foo">
     :
     <xsql:include-xml>
      select your_clob_col from dual
       where ...predicate-to-return-a-single-row...
     </xsql:include-xml>  
   </yourpage>

to return XML in a CLOB as XML in an XSQL page.

5.10.How to specify a DTD While transforming XSQL output to a WML doument?

Question:
I am trying to create a demo using XSQL demo. It works fine with Apache server. Now I am trying to write my own stylesheet for transforming XSQL output to WML and VML format. These programs (mobile phone simulators) need a WML document with a specific DTD assigned. Is there any way, I can specify a particular DTD while transforming XSQL output to a WML document.

Answer:
The way you do it is using a built-in facility of the XSLT Stylesheet called

<xsl:output/>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output type="xml" doctype-system="your.dtd"/>
<xsl:template match="/technology/">
</xsl:template>
:
:
</xsl:stylesheet>

This will produce an XML result with a:

<!DOCTYPE xxxx SYSTEM "your.dtd">

in the result. "your.dtd" can be any valid absolute or relative URL.

5.11.How to use the CURSOR Operator for Nested Structure ?

Question:
1.The generated code has a top-level Element "<EMPLOYEES>". I want to get rid of it as per out requirements. 2.How can I specify id_attribute and id-attribute-column for the inner nested query e.g. <myEmployee myEmployee_id="1001"> Currently I am using "include-xsql" and manual deletion as a work-around. I believe most of the XSDs getting out of Oracle will be complex having nested structures. Just to give you an idea, I am working on an XSD such as the following: Budget Worksheet Positions Elements Element Distributions FTE Distributions accounts Though work-arounds are available using XSLT, include-xsql, and so on, they involve additional work. Will XSQL support it?

Answer:
1. The generated code has a top-level Element "<EMPLOYEES>". I want to get rid of it as per out requirements. Unfortunately, today we do not support renaming columns or attributes or hiding them directly with the utility. The only way to do it is to use an XSLT stylesheet (simple stylesheet which simply removes the EMPLOYEES tag). 2. How can I specify id_attribute and id-attribute-column for the inner nested query e.g. <myEmployee myEmployee_id="1001"> Again, we do not support this yet. You can do it with XSLT.

5.12.Is it possible for me to put any conditional queries in the .xsql file itself?

Question:
For example: If I have three parameters, depending on what is populated, I want the query string to be formed. Is it possible for example to state:


if(p1=NULL)
  <qurey1>.....</query1>
if (p2=NULL)
<query1>.....</query2>

and so on?

Answer:
A better way is to do a selection on a client side using Javascript. XSQL is not a language so it is very limited in terms of selection and looping. Are the three different choices radically different, or slight variations of WHERE clauses against the same table? If the latter, you can do the following:

SELECT .... FROM TABLE WHERE ( ({@p1}='yes') and (...something...))
or
( {{@p2}='yes') and (...something else...))

5.13.What's wrong if I got "ClassNotFoundException" running XSQL Servlet?

Question:
I've set up Apache (1.3.9) + JServ + XSQL Servlet as explained in the XSQL servlet release notes. When I try to run:

http://127.0.0.1/xsql/demo/helloworld.xsql

I see the following entry in mod_jserv.log :

[11/10/1999 20:25:47:383]
     (ERROR) ajp12:Servlet Error: ClassNotFoundException: oracle.xml.xsql.XSQLServlet

Answer:
Within your jserv.properties file make sure the following jar files is added as below and expecially oraclexsql.jar is for XSQL Servlet:

wrapper.classpath=C:\xsql\lib\classes12.zip: :
        wrapper.classpath=C:\xsql\lib\xmlparserv2.jar: :
        wrapper.classpath=C:\xsql\lib\xsu12.jar
        wrapper.classpath=C:\xsql\lib\oraclexsql.jar  

5.14.Why I can't see any results when trying to get out parameter from a stored procedure?

Question:
I using <xsql:dml>to call a stored procedure which has one OUT parameter, but I was not able to see any results. The executed code results in the following statement: <xsql-status action="xsql:dml" rows="0"/>

Answer:
You cannot set parameter values by binding them in the position of OUT variables in this release using <xsql:dml>. Only IN parameters are supported for binding. You can create a wrapper procedure that constructs XML elements using the HTP package and then your XSQL page can invoke the wrapper procedure using <xsql:include-owa> instead.

For an example, suppose you had the following procedure:

CREATE OR REPLACE PROCEDURE addmult(arg1 NUMBER,arg2 NUMBER,sumval  OUT NUMBER, prodval OUT NUMBER) IS
BEGIN    
  sumval := arg1 + arg2;  
  prodval := arg1 * arg2;
END;

You could write the following procedure to "wrap" it, taking all of the IN arguments that the procedure above expects, and then "encoding" the OUT values as a little XML datagram that you print to the OWA page buffer:

CREATE OR REPLACE PROCEDURE addmultwrapper(arg1 NUMBER, arg2 NUMBER) IS  
  sumval  NUMBER;  
  prodval NUMBER;  
  xml     VARCHAR2(2000);
BEGIN  
  -- Call the procedure with OUT values  
  addmult(arg1,arg2,sumval,prodval);  

  -- Then produce XML that encodes the OUT values    
  xml := '<addmult>'|| '<sum>'| |sumval| |'</sum>'
       || '<product>'| |prodval| |'</product>'
       || '</addmult>';  

  -- Print the XML result to the OWA page buffer for return  
  HTP.P(xml);
END;

This way, you can build an XSQL page like this that calls the wrapper procedure:

<page connection="demo" xmlns:xsql="urn:oracle-xsql">  
<xsql:include-owa bind-params="arg1 arg2">    
  BEGIN addmultwrapper(?,?); END;  
</xsql:include-owa>
</page>

This allows a request like:

http://yourserver.com/addmult.xsql?arg1=30&arg2=45

to return an XML datagram that reflects the OUT values like this:

<page>
    <addmult>
      <sum>75</sum>
      <product>1350</product>
    </addmult>
</page>

5.15.Why I got " java.text.ParseException: Unparseable date: "?

Question:
Whilst using the DBMS_XMLSave.updateXML procedure I am having problems parsing a date which is the format dd/mm/yy
I have tried to use the following procedure to set the date format :

DBMS_XMLSave.setDateFormat(updCtx,'DD/MM/YY');

Unfortunately it is not working, as the parser still does not recognise the date format, it seems to want the time element.
please may somebody advise on some possible solutions

Answer:
The date formats must match java date formats not Oracle date formats. For a list of valid date formats please check
http://java.sun.com/products/jdk/1.1/docs/api/java.text.SimpleDateFormat.html
In

<xsql:insert/>

and

<xsql:update/>

there is date-format attribute for you to specify the date format.

5.16.why I got "XSQL page is not well-formed" when using xsql:include-xml?

Question:
I can't seem to figure out how to use the <xsql:include-xml> tag correctly.


<?xml version="1.0"?>
<xsql:include-xml href="fees.xml"/>

Those are the first two lines in my .xsql file and I get this error:

XSQL-005: XSQL page is not well-formed.
XML parse error at line 2, char 36
Namespace prefix 'xsql' used but not declared.

Why?

Answer:
I believe that you need to specify the namespace for XSQL in your file. I have a similar example (although adding a stylesheet) and it works ok.

Example:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="os05.xsl"?>
<xsql:include-xsql href="os05_x.xsql" xmlns:xsql="urn:oracle-xsql"/>

The xmlns:xsql="urn:oracle-xsql" is vital in that example, and I think it is your problem.

back to top

6.0 Class Generator

6.1.How do i install XML Java Class Generator?

Answer:
The Class Generator is packaged as part of the XDK and so you do not have to download it separately. The CLASSPATH should be set to include classgen.jar, xmlparserv2.jar, and xschema.jar which are located in the lib/ directory and not in the bin/ directory.

6.2.What does the XML Class Generator for Java do?

Question:
How do I use the XML Class Generator for Java to get XML data?

Answer:
XML Class Generator for Java creates Java source files from an XML DTD or XML Schema . This is useful when an application wants to send an XML message to another application based on an agreed-upon DTD/Schema or as the back end of a web form to construct and XML document. Using these classes, Java applications can construct, validate, and print XML documents that comply with the input DTD/Schema. The Class Generator works in conjunction with the Oracle XML Parser for Java v2, which parses the DTD and passes the parsed document to the class generator.

To get XML data, first, get the data from the database using JDBC ResultSets. Then, instantiate objects using the classes generated by the XML Class Generator.

6.3.Why I got class generator error: Expected 'DOCTYPE' ?

Question:
we're trying to generate classes from a dtd and we get the error:

Error: DTD Class Generator failed to generate classes. oracle.xml.parser.v2.XML
ParseException: Expected 'DOCTYPE'.

Which is the expected DOCTYPE? We're using this example dtd:


<!-- DTD for Employee Data -->
<!ELEMENT EMP (EMP_ROW)*>
<!ELEMENT EMP_ROW (EMPNO, ENAME?, JOB?, MGR?, HIREDATE?, SAL?, COMM?, DEPTNO?)>
<!ATTLIST EMP_ROW ROWNO CDATA #REQUIRED>
<!ELEMENT EMPNO (#PCDATA)>
<!ELEMENT ENAME (#PCDATA)>
<!ELEMENT JOB (#PCDATA)>
<!ELEMENT MGR (#PCDATA)>
<!ELEMENT HIREDATE (#PCDATA)>
<!ELEMENT SAL (#PCDATA)>
<!ELEMENT COMM (#PCDATA)>
<!ELEMENT DEPTNO (#PCDATA)>

Answer:
Since you using DTD file directly, please specify the ROOT ELEMENT Name by

-root EMP

Here is the command how I generate classes for your DTD using demo program:

java SampleMain -root EMP [dtdfilename]

back to top

7.0 XML JavaBeans

7.1.What is Oracle XML Transviewer Beans?

Answer:
Oracle XML Transviewer beans facilitate the addition of graphical or visual interfaces to your XML application. You could use oracle XML Transviewer Java Beans to transform XML by XSL stylesheet, store XML document back to database, with XSU to do database queries to materialize XML etc.

7.2.Where I can get Oracle XML Transviewer Beans?

Answer:
Oracle XML Transviewer Beans are provide with Oracle 8i Enterprise and Standard Editions from Release 2 (8.1.6) and higher. If you don't have these editions you can download the beans from: /tech/xml

7.3.Why I get "XMLSource View not found in class ViewSample" when I compile/run ViewSample.java?

Answer:
All the oracle specific classes are included in the /lib/xmlcomp.jar and /lib/xmlparserv2.jar which is part of the XML Transviewer Java Beans download. Make sure that your classpath specifies the path as well as the name of the jar files.

back to top

8.0 Oracle SOAP

8.1.Does SOAP replace COM or CORBA?

Answer:
No. COM is a component model. CORBA is a specification of services that are useful for building distributed applications. SOAP is simply a communication protocol that COM or CORBA objects can use to communicate.

8.2.Is SOAP tied to any particular programming language?

Answer:
SOAP says nothing about language bindings, rather it is simply a wire protocol. The protocol is simple and non-intrusive enough that any tool vendor that supports HTTP will be able to easily support SOAP. The basic Perl implementation, for instance, took about half a month for one person to implement. This simplicity is one of the things that makes SOAP attractive.

8.3.What is SOAP?

Answer:
SOAP is a protocol specification for invoking methods on servers, services, components and objects. SOAP codifies the existing practice of using XML and HTTP as a method invocation mechanism. The SOAP specification mandates a small number of HTTP headers that facilitate firewall/proxy filtering. The SOAP specification also mandates an XML vocabulary that is used for representing method parameters, return values, and exceptions.

back to top

9.0 TransX Utility

9.1.What is the Oracle TransX Utility?

Answer:
TransX is a data transfer utility that allows you to populate your database with multilingual data. It uses XML to specify the data so you can take advantage of easy data transfer from XML to the database, a simple data format that is intuitive for both developers and translators, and validation capability that makes it less error prone.

9.2.What kind of interfaces does TransX Utility provide?

Answer:
TransX has a command line interface and programmatic interface. Both of them are straightforward and require little time to get familiar with. Details will be discussed in the next section. All the functionalities of TransX are accessible through both the command line interface and the Java API.

back to top

/HTML
E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy