![]() | ![]() |
Home |
|
|
XML Services in Adaptive Server Enterprise |
|
| Appendix D Migrating Between the Java-based XQL Processor and the Native XML Processor |
Appendix D
The Java-based XQL processor and the native XML processor are similar but different. They both implement query languages and return documents in parsed form, but they use different functions and methods.
The native XML processor implements XML query language. It provides a built-in function, xmlparse, that returns, in parsed form, a document suitable for efficient processing with the xmlextract and xmltext built-in functions.
The Java-based XQL processor is an earlier facility that implements the XQL query language. It provides a Java method, com.sybase.xml.xql.Xql.parse, that returns a parsed form of a document that is a sybase.aseutils.SybXmlStream object, suitable for processing with the com.sybase.xml.xql.Xql.query method.
If you want to migrate documents between the Java-based XQL processor and the native XML processor, you should be aware of the following possibilities and restrictions:
Documents in text form can be processed directly by both the Java-based XQL processor and the native XML processor.
The sybase.aseutils.SybXmlStream documents generated by com.sybase.xml.xql.Xql.parse can only be processed by the Java-based XQL processor. They cannot be processed by the built-in functions xmlextract or xmltest.
The parsed documents generated by the xmlparse built-in function can only be processed by the xmlextract and xmltest built-in functions. They cannot be processed by the Java-based XQL processor.
The following sections describe techniques for migrating documents and queries between the Java-based XQL processor and the native XML processor.
The native XML processor supports only ASCII data for XML documents. The Java-based XQL processor supports additional character sets, including Unicode. Documents with such data cannot be processed by the native XML processor.
There are two approaches you can use to migrate documents between the Java-based XQL processor to the native XML processor:
You can use the text form of the documents, if it is available.
You can generate a text version of the documents from the parsed form of the documents.
Suppose that you have a table such as the following, in which you have stored the text form of documents in the xmlsource column:
create table xmltab (xmlsource text, xmlindexed image)
If you want to process the documents with the native XML processor, using the xmlextract and xmltest built-in functions, you can update the table as follows:
update xmltab set xmlindexed = xmlparse(xmlsource)
If you want to process the documents with the Java-based XQL processor, using the com.sybase.xml.xql.Xql.query method, you can update the table as follows:
update xmltab
set xmlindexed
= com.sybase.xml.xql.Xql.parse(xmlsource)Suppose that you have stored only parsed forms of some documents, using either the xmlparse built-in function for the native XML processor or the com.sybase.xml.xql.Xql.parse method for the Java-based XQL processor. For example, you might have such documents in a table as the following:
create table xmltab (xmlindexed image)
If you want to regenerate the text for such documents, you can alter the table to add a text column:
alter table xmltab add xmlsource text null
This section demonstrates regenerating the text form of the documents from the form generated for the Java-based XQL processor.
If the xmlindexed column contains sybase.aseutils.SybXmlStream data generated by com.sybase.xmlxql.Xql.parse, you can regenerate the text form of the document in the new xmlsource column with the following SQL statement:
update xmltab
set xmlsource
= xmlextract("/xql_result/*",
com.sybase.xml.xql.Xql.query("/",xmlindexed) )This statement generates text form of the document in two steps:
The com.sybase.xml.xql.Xql.query call with the "/" query generates a text form of the document, enclosed in an XML tag <xql_result>...</xql_result>.
The xmlextract call with the "/xql_result/*" query removes the <xql_result>...</xql_result> tag, and returns the text form of the original document.
You can then process the xmlsource column directly with the native XML processor, using the xmlextract and xmltest built-in functions, or you can update the xmlindexed column for the native XML processor, as follows:
update xmltab set xmlindexed = xmlparse(xmlsource)
If you don't want to add the xmlsource column, you can combine these steps, as in the following SQL statement:
update xmltab
set xmlindexed
= xmlparse(xmlextract("/xql_result/*",
com.sybase.xml.xql.Xql.query("/",xmlindexed) ) )Before this update statement is executed, the xmlindexed column contains the sybase.aseutiles.SybXmlStream form of the documents, generated by the com.sybase.xml.xql.Xql.parse method. After the update statement, that column contains the parsed form of the documents, suitable for processing with the xmlextract and xmlparse methods.
This section demonstrates regenerating the text form of the documents from the form generated for the native XML processor.
If the xmlindexed column contains data generated by the xmlparse function, you can regenerate the text form of the document in the new xmlsource column with the following SQL statement:
update xmltab
set xmlsource = xmlextract("/", xmlindexed)You can then
process the xmlsource column directly with the Java-based XQL processor, using com.sybase.xml.xql.Xql.query, OR
update the xmlindexed column with the parsed form suitable for processing with the Java-based XQL processor, using the following statement:
update xmltab set xmlindexed = com.sybase.xml.xql.Xql.parse(xmlsource)
If you don't want to add the xmlsource column, you can combine these steps, as in the following SQL statement:
update xmltab
set xmlindexed
= com.sybase.xml.xql.Xql.parse
(xmlextract("/", xmlindexed)) Before this update statement is executed, the xmlindexed column contains the parsed form of the documents, generated by the xmlparse built-in function. After the update statement, that column contains the parsed form of the documents, generated by com.sybase.xml.xql.Xql.parse, suitable for processing with com.sybase.xml.xql.Xql.query.
The XQL language implemented by the Java-based XQL processor and the XML Query language implemented by the native XML processor are both based on the XPath language. There are two primary differences between them:
Subscripts begin with "1" in the XML Query language, and with "0" in the XQL Language.
The Java-based XQL processor returns results enclosed in "<xql_result>...</xql_result>" tags, and the native XML processor does not.
|
|