title: XMLAdapter: Configurable Date Format
body: <p>I'm unmarshaling XML data using JAXB (and a little Saxon for XSLTs). In my XML document I have a date string value.</p>
  
  <p>I did some research and experimented with XMLAdapter and @XMLJavaTypeAdapter. I found a useful Q&amp;A on StackOverflow here: <a href="https://stackoverflow.com/questions/2519432/jaxb-unmarshal-timestamp">jaxb unmarshal timestamp</a>. The solution outlined there involving a SimpleDateFormat seems to work well.</p>
  
  <p>Here is my problem: The format of the date string in the XML is variable from document to document. It can be in a different date format each time. In the current system (that I am replacing with all this XML manipulation) there are date formats in database tables that are retrieved and applied when the XML document is parsed. Manually. Line by line. (Now you see why I'm replacing it with JAXB, yeesh!)</p>
  
  <p><strong>So the question would be:</strong> How would I change out the date format string being fed to the SimpleDateFormat in the XMLAdapter for different documents? Is such a thing even possible? Am I doomed to reading the date string out as a String and then converting it to a Date somewhere else later on?</p>
  
  <p><strong>Edit:</strong> I was just going to delete this question, but it got up-voted, so I guess I'll write out a proper answer to it as to what I ended up doing. I'm going to hold off on accepting my own answer for awhile, in case anyone has some insight that leads to an even better answer.</p>