| By Deepak Vohra, Ajay Vohra | Article Rating: |
|
| June 11, 2008 02:00 PM EDT | Reads: |
3,650 |
XML processing in ASE is done with XQL and the ResultSetXml class.
XQL
With XQL (the XML query language), SQL data in a database can be represented as an XML document. XQL is implemented with the com.sybase.xml.xql.Xql class. The XQL class is the interface to the XML query engine.
Parse (String xmlDoc)
‘xmlDoc’ is a String representing an XML document. The
return type of the parse() method is SybXmlStream, which may be used to query a
document with XQL. For example, an XML document stored in a database table
(XMLDAT) column (xmldoc) can be updated with the parse() method as shown below.
update XMLDAT
set
xmldoc=com.sybase.xml.xql.Xql.parse(“<xmldoc></xmldoc>”)
parse(InputStream xml_document, boolean validate)
- ‘xml_document’ is an InputStream representing an XML document.
- If ‘validate’ is true an XML document is validated with a specified DTD.
The return type of the parse() method is SybXmlStream, which can be used to query a document with XQL. For example, an XML document stored in a database table (XMLDAT) column (xmldoc) can be updated with the parse() method as shown below.
update XMLDAT
set xmldoc=com.sybase.xml.xql.Xql.parse(new
FileInputStream(“file.xml”), true);
setParser(String parserName)
- The setParser() method specifies the parser for the parse() method.
- The default parser is xerces-1.3.1
query(String query, String xmlDoc)
- ‘query’ is a String representing an XML element or attribute. The parameter ‘xmlDoc’ is the XML document being queried. The return type of the query() method is a String.
For example, an element or an attribute can be retrieved from an XML document as shown here.
String result=Xql.query(“catalog/journal”, “<xml>...</xml>”);
query(String query, InputStream xmlDoc)
- ‘query’ is a String representing an XML element or attribute. ‘xmlDoc’ is an InputStream representing an XML document. The return type of the query() method is a String.
For example, an element or an attribute can be retrieved from an XML document.
String result=Xql.query(“/catalog/journal”, “new FileInputStream(“file.xml”)”);
ResultSetXml Class
A ResultSetXml class is a subclass of the JXML class. An XML
document can be generated from a SQL result set with the xml.resultset.ResultSetXml
class. The ResultSetXml class is also used to modify the XML document generated
from a SQL result set. The modified ResultSetXml object can be converted to SQL
data in the database. A ResultSetXml object is created from an XML ResultSet
document or SQL query. An XML ResultSet document is an XML document that
validates with the XML ResultSet DTD. The XML ResultSet DTD is illustrated in
Listing 1.
Generating ResultSetXml from an XML ResultSet Document
A ResultSetXml object can be generated from an XML ResultSet document.
xml.resultset.ResultSetXml rsx = new xml.resultset.ResultSetXml(“XmlDocument”);
- ‘XmlDocument’ is a String variable containing an XML ResultSet document.
The ResultSetXml(“Xml ResultSet document”) constructor also validates the XML ResultSet document.
Generating ResultSetXml from a SQL Result Set
With the ResultSetXml class an XML ResultSet document can be generated from a SQL query as shown here.
xml.resultset.ResultSetXml
rsx =
new
xml.resultset.ResultSetXml (query, cdata
Columns, colNames, server);
- query is an SQL query that returns a result set.
- cdataColumns indicates which columns should be XML CDATA sections.
- colNames indicates if the resulting XML should specify “name” attribute in the “Columns” element.
- server specifies the Adaptive server on which to execute the query.
The ResultSetXml class has methods to access and update the elements of an XML document and can be used to validate an XML result set document with the XML ResultSet DTD.
String getColumn(int rowNumber, int columnNumber)
- ‘rowNumber’ is the index of a row in the result set.
- ‘columnNumber’ is the index of a column in the result set.
For example, Select rsx>>getColumn(3,4) returns the String value of the fourth column in the third row. rsx is a ResultSetXml variable.
String getColumn(int rowNumber, int columnName)
- ‘rowNumber is the index of a row in the result set.
- ‘columnNumber’ is the name of a column in the result set. For example, Select rsx>>getColumn(3, “columnName”) returns the String value of the ‘columnName’ coulmn in the third row.rsx is a ResultSetXml variable.
void setColumn(int rowNumber, int columnNumber, newValue)
- ‘rowNumber’ and ‘columnNumber’ are the same as for getColumn() methods.
- The setColumn() methods sets the value of the specified column to ‘newValue’.
For example, Select rsx=rsx>>setColumn(3,4,”new value”) sets the column value of the column in the fourth column and the third row to ‘new value.’
void setColumn(int rowNumber, String columnName, newValue)
- ‘rowNumber’ and ‘columnNumber’ are as specified for getColumn() methods.
- The setColumn() method sets the value of the specified column name to ‘newValue.’
For example, select rsx=rsx>>setColumn(3, “columnName”, “new value”) sets the column value of ‘columnName’ column in the third row to ‘new value.’
Conclusion
The Adaptive Server Enterprise 12.5 has integrated support
for XML data management.
XML data can be stored in a database and data in a database can be converted into an XML document. XQL and ResultSetXml classes are used to store, index, and query XML data in a database.
Published June 11, 2008 Reads 3,650
Copyright © 2008 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Deepak Vohra
Deepak Vohra is a Sun Certified Java 1.4 Programmer and a Web developer.
More Stories By Ajay Vohra
Ajay Vohra is a senior solutions architect with DataSynapse Inc.
- Why SOA Needs Cloud Computing - Part 1
- Cloud Expo and The End of Tech Recession
- The Transition to Cloud Computing: What Does It Mean For You?
- A Rules Engine Built in PowerBuilder
- Sybase Named “Silver Sponsor” of iPhone Developer Summit
- How PowerBuilder Got Its Groove Back
- The Cloud Has Cross-Border Ambitions
- Ulitzer Named "New Media" Partner of Greatly Anticipated iStrategy Event in Berlin
- Risks and Enterprise Mobility?
- Steps for Success in Enterprise Mobility?
- Are Mobile Luddites Resisting Mobility?
- Hot Event in Santa Clara Becomes Cool with the iPhone
- The Difference Between Web Hosting and Cloud Computing
- Sybase CTO to Speak at 4th International Cloud Computing Expo
- Why SOA Needs Cloud Computing - Part 1
- Cloud Expo and The End of Tech Recession
- The Transition to Cloud Computing: What Does It Mean For You?
- Five Reasons to Choose a Private Cloud
- Seeding The Cloud: The Future of Data Management
- The Threat Behind the Firewall
- Economy Drives Adoption of Virtual Lab Technology
- Tips for Efficient PaaS Application Design
- A Rules Engine Built in PowerBuilder
- Sybase Named “Silver Sponsor” of iPhone Developer Summit
- Where Are RIA Technologies Headed in 2008?
- PowerBuilder History - How Did It Evolve?
- The Top 250 Players in the Cloud Computing Ecosystem
- Custom Common Dialogs Using SetWindowsHookEx
- DDDW Tips and Tricks
- OLE - Extending the Capabilities of PowerBuilder
- DataWindow.NET How To: Data Entry Form
- Book Excerpt: Sybase Adaptive Server Anywhere
- Sybase ASE 12.5 Performance and Tuning
- Working with SOA & Web Services in PowerBuilder
- Office 2003 Toolbar: A New Look For Your Old PowerBuilder App
- Dynamically Creating DataWindow Objects


































