![]() | ![]() |
Home |
|
|
XML Services in Adaptive Server Enterprise |
|
| Appendix D Migrating Between the Java-based XQL Processor and the Native XML Processor |
|
| Migrating documents and queries |
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.
|
|