XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
David IsaacSubject: Problems with Java date parameters using DDTEK XQuery engine
Author: David Isaac
Date: 29 Jun 2009 10:39 AM
Hello-

Has anyone successfully passed a date parameter from XQuery to Java using the ddtek XQuery engine?

With SAXON, I can successfully do the following:

declare namespace sdf = "java:java.text.SimpleDateFormat";
declare function local:toDate($stringDate as xs:string?) as xs:dateTime? {
let $format := sdf:new("MM/dd/yyyy")
return sdf:parse($format, $stringDate)
};

which nicely converts the returned Java Date to xs:dateTime.
With DDTEK, I tried unsuccessfully to do the following:

declare namespace sdf = "ddtekjava:java.text.SimpleDateFormat";
declare function sdf:SimpleDateFormat($format as xs:string) as ddtek:javaObject external;
declare function sdf:parse($this as ddtek:javaObject, $stringDate) as ddtek:javaObject external;
declare function local:convert($stringDate as xs:string as xs:date {
let $format := sdfSimpleDateFormat("MM/dd/yyyy")
return xs:dateTime(sdf:parse($format,$stringDate))
};

The ddtek:javaObject returned from parse is not automatically converted to xs:date and cannot be cast either. Any hints what I am doing wrong? I cannot find any default mapping of date types between Java and XQuery in the ddtek documentation, so perhaps it can't be done? Am I approaching this all wrong...is there really no better way to convert dates? Sometimes I am simply trying to process dates in mm/dd/yyyy hh:mm:ss format, and of course XQuery requires ISO yyyy-mm-dd etc. format...is there really no implicit conversion for this common format? Any help would be greatly appreciated!

Postnext
Alberto MassariSubject: Problems with Java date parameters using DDTEK XQuery engine
Author: Alberto Massari
Date: 30 Jun 2009 12:05 PM
Hi David,
the table listing the mapping used by DDXQ to convert between Java and XQuery datatypes is Table 13-1 in chapter 13 of the User Guide (that can be found at <Stylus Studio Install>\Components\DataDirect XQuery\books\ddxquery\ddxqug\ddxqug.pdf).
Unfortunately the java.util.Date type is not automatically converted into xs:date, so you must do one extra step to convert it into a string suitable for constructing an xs:date item.

declare namespace sdf = "ddtekjava:java.text.SimpleDateFormat";
declare function sdf:SimpleDateFormat($format as xs:string) as ddtek:javaObject external;
declare function sdf:parse($this as ddtek:javaObject, $stringDate) as ddtek:javaObject external;
declare function sdf:format($this as ddtek:javaObject, $objDate) as xs:string external;

declare function local:convert($stringDate as xs:string) as xs:date {
let $format := sdf:SimpleDateFormat("MM/dd/yyyy")
let $formatISO := sdf:SimpleDateFormat("yyyy-MM-dd")
return xs:date(sdf:format($formatISO, sdf:parse($format,$stringDate)))
};


Hope this helps,
Alberto

Posttop
David IsaacSubject: Problems with Java date parameters using DDTEK XQuery engine
Author: David Isaac
Date: 07 Jul 2009 05:04 PM
I get it. Thanks!

PS: Implicit Java date type conversion might be a nice feature to add... :)

 
Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.