File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Translating one XML to another XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Translating one XML to another XML" Watch "Translating one XML to another XML" New topic

Translating one XML to another XML

Marla Arnett

Joined: Jul 09, 2010
Posts: 5
Taking certain elements from one XML doc and translating them into another XML doc where the element is of a different type. For example: One XML has a <xs:element name="QuoteEffDate" type="xs:date" minOccurs="0"> ; the other XML has an <xs:element name="effectiveDate" type="xs:string" />

I am trying to get the QuoteEffDate value transformed from a date type to a string type.public class DateTranslator implements Translator {
Here is my logic so far, I have a Date Translator:

then I do a Marshal process which will exectute a Mapper method:
AT THIS POINT I AM TAKING AN ERROR because the getQuoteEffDate() is of Calendar type and it has a string value.

[969] - [2010-07-20 10:42:35,718] - [ERROR] - [com.principal.soldcasefeed.jobsteps.SoldCaseFeedXDStep1.processJobStep(Line Number:71)] - [org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException: Invalid date value: wrong type: 11152010]

What am I doing wrong and how can I fix it?

Greg Charles

Joined: Oct 01, 2001
Posts: 2849

Hi Marla, and welcome to Java Ranch.

There are a few things to do to make it easier (and thus more likely) for us to answer your questions. The main one is learn to use code tags. Actually, there's not much to learn, and it makes reading code in the forum much, much easier. Also, your error reports line number, so it would be useful to know which line that is in the code you posted. Maybe that's what you meant with the bold face lines.

Now, I'm a little confused to what you're doing. You say you're translating an XML file, but what you've posted looks like XSD to me. Are you trying to transform the XML document specified by that XSD, or the XSD itself? Obviously, the XSD doesn't have dates in it; it just specifies where dates are allowed in the XML. So if you're trying to convert a string like xs:date to a date or calendar object, then you are going to have a problem.
Marla Arnett

Joined: Jul 09, 2010
Posts: 5
hello and thanks.

Thanks for the tip about using the source tags I will remember that in the future.

the XML that is parsed has an element <QuoteEffDate>2010-11-15</QuoteEffDate> and the XML that I need to pass this information on to has an element <effectiveDate> </effectiveDate> however the value in this element must be a string in the format of 11152010.

does this help? the error is occuring when this statement trys to execute: quoteData.getQuoteEffDate(); when I put my mouse over this in RAD it tells me that the getQuoteEffDate() method is Calendar com.connecture.schemas.TypeQuoteData.getQuoteEffDate(). I am interpreting this to mean that this is of a Calendar type and this is why I am getting the error because it is trying to return the value 11152010 which is a string type.

David Newton

Joined: Sep 29, 2008
Posts: 12617

You can edit your post by using the button.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38441
David Newton wrote:You can edit your post by using the button.
Since she's new I've done it for her.
Richard Golebiowski
Ranch Hand

Joined: May 05, 2010
Posts: 213

To me it looks like you're trying to put the cart before the horse. You are converting the date to a string when it is being read from the XML, but the subsequent method, getQuoteEffDate, is expecting something in the form of a date. Do the conversion before writing it to the next XML file.
subject: Translating one XML to another XML