How to map database XML output to JAXB derived object model
I am requesting links to sources/material that will help me with the following problem (a problem because I am novice to Java/JAXB and coming from a PHP background).
I am supplied with a complex XSD that is created & maintained by an organization. I created the java object model using JAXB 2.1. I need to map database fields to the java/jaxb derived classes. The database fields/elements are rendered via simple XML output. Example of the XML database record output is as follows:
<PROBLEM>
<PID>262</ID>
<PROBLEM_DATE>14-DEC-10<开发者_JS百科/PROBLEM_DATE>
<PROBLEM_TYPE>T</PROBLEM_TYPE>
<PROBLEM_CODE>244.9</PROBLEM_CODE>
</PROBLEM>
Example of of the JAXB derived class:
protected IvlTs problemDate;
public IvlTs getProblemDate() {
return problemDate;
}
public void setProblemDate(IvlTs value) {
this.problemDate = value;
}
How would I map the xml element <PROBLEM_DATE>
to problemDate? Please advise of an article/tutorial that can help me get started. Also, the XML database extract is large, having nearly 500 fields/xml elements, is there a way to automate the mapping or must this all be done by hand?
You'll want to read up on JAXB annotations. For this particular problem, you want to annotate the getProblemDate() method with
@XmlElement(name="PROBLEM_DATE")
If there's a common pattern, like problemDate -> PROBLEM_DATE and in general fooBar -> FOO_BAR, then it should be pretty easy to write a regex find/replace to get what you need.
精彩评论