Thursday, August 30, 2007

XML Error: NoClassDefFoundError: org/w3c/dom/ranges/DocumentRange

error
java.lang.NoClassDefFoundError: org/w3c/dom/ranges/DocumentRange

environment
The following xml jars are in my classpath:
xerces.jar - org.apache.*, org.w3c.dom.html.*, org.w3c.dom.ls.*
xercesImpl.jar - com.sun.org.apache.*


possible causes:
You are missing the DocumentRange class in your classpath.

solution
You may either include dom.jar or xml-apis.jar in your classpath.

Wednesday, August 29, 2007

Pivot Tables

Example:

SELECT *
FROM (SELECT job,
sum(decode(deptno,10,sal)) DEPT10,
sum(decode(deptno,20,sal)) DEPT20,
sum(decode(deptno,30,sal)) DEPT30,
sum(decode(deptno,40,sal)) DEPT40
FROM scott.emp
GROUP BY job)
ORDER BY 1;
If you are pivoting over varchar fields, you can use the max or min aggregate function because these can operate on varchar fields.

Example:

SELECT language_id,
max(decode(greeting,'hello', sal)) english,
max(decode(greeting,'konichiwa',sal)) japanese,
max(decode(greeting,'ni hao',sal)) chinese,
max(decode(greeting,'ola',sal)) spanish
FROM language.phrases
GROUP BY language_id


References:
How does one code a matrix/crosstab/pivot report in SQL?
Pivot Table Techniques

Tuesday, August 28, 2007

Java XML Binding Frameworks

Apache Axiom ~ AXis Object Model
Castor XML
JAXB ~ Java Architecture for XML Binding
JBind
JiBX
XMLBeans

Dom4j Schema Validation

XML:

<?xml version="1.0"?>
<reportingConfig xmlns="http://services.bamnetworks.com/reporting/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://services.bamnetworks.com/reporting/ reporting-config.xsd"
>
...
</reportingConfig>


XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://services.bamnetworks.com/reporting/"
xmlns:tns="http://services.bamnetworks.com/reporting/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
>
...
</xsd:schema>


Java code:


import org.dom4j.io.SAXReader;
import org.dom4j.Document;
....

SAXReader reader = new SAXReader(true);

reader.setFeature("http://apache.org/xml/features/validation/schema", true);

// set the validation feature to true to report validation errors
reader.setFeature("http://xml.org/sax/features/validation", true);

// set the validation/schema feature to true to report validation errors against a schema
reader.setFeature("http://apache.org/xml/features/validation/schema", true);

// set the validation/schema-full-checking feature to true to enable full schema, grammar-constraint checking
reader.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);

Document document = reader.read(reportingConfigURL);