I'm fairly new with JAVA and encountered a very specific problem:
I have a web service which return regularly XML messages. I want to be able to deserialize this message into a JAVA object but i don't know how to proceed further...
This is a basic xml message i receive :
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ds:tfmDataService
xmlns:ds="urn:us:gov:dot:faa:atm:tfm:tfmdataservice"
xmlns="urn:us:gov:dot:faa:atm:tfm:tfmdataservice"
xmlns:fdm="urn:us:gov:dot:faa:atm:tfm:flightdata"
xmlns:nxce="urn:us:gov:dot:faa:atm:tfm:tfmdatacoreelements"
xmlns:nxcm="urn:us:gov:dot:faa:atm:tfm:flightdatacommonmessages"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:us:gov:dot:faa:atm:tfm:tfmdataservice TFMData_Service.xsd">
<fltdOutput>
<fdm:fltdMessage acid="UAL1252" airline="UAL" arrArpt="KIAH" cdmPart="true" depArpt="KSAT" fdTrigger="FD_FLIGHT_MODIFY_MSG" flightRef="125539563" msgType="FlightModify" sensitivity="A" sourceFacility="UAL" sourceTimeStamp="2020-01-27T09:32:11Z">
<fdm:ncsmFlightModify>
<nxcm:qualifiedAircraftId>
<nxce:aircraftId>UAL1252</nxce:aircraftId>
<nxce:computerId>
<nxce:facilityIdentifier>UAL</nxce:facilityIdentifier>
</nxce:computerId>
<nxce:igtd>2020-01-27T23:30:00Z</nxce:igtd>
<nxce:departurePoint>
<nxce:airport>KSAT</nxce:airport>
</nxce:departurePoint>
<nxce:arrivalPoint>
<nxce:airport>KIAH</nxce:airport>
</nxce:arrivalPoint>
</nxcm:qualifiedAircraftId>
<nxcm:airlineData>
<nxcm:flightStatusAndSpec>
<nxcm:flightStatus>FILED</nxcm:flightStatus>
<nxcm:aircraftModel>B739</nxcm:aircraftModel>
<nxcm:aircraftspecification aircraftEngineClass="JET" numberOfAircraft="1">B739</nxcm:aircraftspecification>
</nxcm:flightStatusAndSpec>
<nxcm:eta etaType="SCHEDULED" timeValue="2020-01-28T00:28:00Z"/>
<nxcm:etd etdType="SCHEDULED" timeValue="2020-01-27T23:42:00Z"/>
<nxcm:flightTimeData airlineInTime="2020-01-28T00:37:00Z" airlineOffTime="2020-01-27T23:42:00Z" airlineOnTime="2020-01-28T00:28:00Z" airlineOutTime="2020-01-27T23:30:00Z" flightCreation="2020-01-26T23:30:38Z" originalArrival="2020-01-28T00:28:00Z" originalDeparture="2020-01-27T23:42:00Z"/>
<nxcm:diversionIndicator>NO_DIVERSION</nxcm:diversionIndicator>
<nxcm:rvsmData currentCompliance="true" equipped="true" futureCompliance="true"/>
<nxcm:arrivalFixAndTime arrTime="2020-01-28T00:03:10Z" fixName="GMANN"/>
</nxcm:airlineData>
</fdm:ncsmFlightModify>
</fdm:fltdMessage>
</fltdOutput>
</ds:tfmDataService>
So first i don't get how i'm supposed to find the schema location since the adress is urn:us:gov:dot:faa:atm:tfm:tfmdataservice TFMData_Service.xsd
I have no clue on how to get this schema description since this adress doesnt looks like a http adress and so i'm not able to extract the schema description since i don't know where to download it.
I understood that i need this schema in order to generate my java class that will be used to deserialize the message into a JAVA object. Is it possible to generate the object on the fly when receiving this type of message or do i really need to first generate the classes to deserialized my messages ?
Then if i'm able to get the xsd describing any xml message received, how am i supposed to generate the code necessary for data deserialization ? How does it work ? Are there specific tools to do that ?
Thanks in advance !
So first i don't get how i'm supposed to find the schema location since the adress is urn:us:gov:dot:faa:atm:tfm:tfmdataservice TFMData_Service.xsd
I have no clue on how to get this schema description since this adress doesnt looks like a http adress and so i'm not able to extract the schema description since i don't know where to download it.
Not all schemas are in the public domain. Often, you need to sign up with the provider organisation before you can get the schemas and/or API specifications.
I understood that i need this schema in order to generate my java class that will be used to deserialize the message into a JAVA object. Is it possible to generate the object on the fly when receiving this type of message or do i really need to first generate the classes to deserialized my messages ?
Java can parse XML without using a schema, but I don't recommend it for this scenario (receiving data from a government API). If there is a schema available - and I would be very surprised if there is not - then you should use it. It will simplify your Java code, and you also have the option of validating against the schema while parsing.
Then if i'm able to get the xsd describing any xml message received, how am i supposed to generate the code necessary for data deserialization ? How does it work ? Are there specific tools to do that ?
That is an easy question to answer using your favourite search engine. Search for 'JAXB'.