SimpleXML with Retrofit 1.9, 'Attribute' version 'does not have a match in class'

I have XML that I need to parse (I have no control over XML or its format):

<?xml version="1.0" encoding="UTF-8"?> <Siri xmlns="http://www.siri.org.uk/siri" version="1.3"> <ResponseTimestamp>2016-01-27T21:49:18.6841619-07:00</ResponseTimestamp> <VehicleMonitoringDelivery version="1.3"> <ResponseTimestamp>2016-01-27T21:49:18.6841619-07:00</ResponseTimestamp> <ValidUntil>2016-01-27T21:49:28.6841619-07:00</ValidUntil> <VehicleActivity> <RecordedAtTime>2016-01-27T21:49:18.6841619-07:00</RecordedAtTime> <MonitoredVehicleJourney> <LineRef>750</LineRef> <DirectionRef>SOUTHBOUND</DirectionRef> <FramedVehicleJourneyRef> <DataFrameRef>2016-01-27T00:00:00-07:00</DataFrameRef> <DatedVehicleJourneyRef>2519014</DatedVehicleJourneyRef> </FramedVehicleJourneyRef> <PublishedLineName>FRONTRUNNER</PublishedLineName> <OriginRef>601084</OriginRef> <DestinationRef>801164</DestinationRef> <Monitored>True</Monitored> <VehicleLocation> <Longitude>-111.86847</Longitude> <Latitude>40.401028</Latitude> </VehicleLocation> <ProgressRate>1</ProgressRate> <CourseOfJourneyRef>18127</CourseOfJourneyRef> <VehicleRef>101</VehicleRef> <MonitoredCall> <StopPointRef>801160</StopPointRef> <VisitNumber>1</VisitNumber> <VehicleAtStop>false</VehicleAtStop> </MonitoredCall> <OnwardCalls> <OnwardCall> <StopPointRef>23076</StopPointRef> <VisitNumber>1</VisitNumber> <StopPointName>OREM CENTRAL STATION</StopPointName> </OnwardCall> </OnwardCalls> <Extensions> <LastGPSFix>2016-01-27T21:49:09.473</LastGPSFix> <Scheduled>False</Scheduled> <Bearing>137.91188191173691</Bearing> <Speed>76.7898894465909</Speed> <DestinationName>Provo</DestinationName> </Extensions> </MonitoredVehicleJourney> </VehicleActivity> </VehicleMonitoringDelivery> </Siri> 

I have a super base and truncated Vehicle class with nothing but a root element, for example:

 import org.simpleframework.xml.Root; @Root(name="VehicleActivity") public class Vehicle { public Vehicle(){} } 

From xml, I'm only interested in the data inside the VehicleActivity tag.

When I try to parse it, from the method of successfully processing the callback, I get the error message Attribute 'version' does not have a match in class :

 01-28 12:49:48.561 30643-30643 E/MY_APP: org.simpleframework.xml.core.AttributeException: Attribute 'version' does not have a match in class com.eduardoflores.utarider.model.Vehicle at line 1 

I know how to do this with JSON, but this is my first attempt to do this using an XML parser.

Any suggestions on what I'm doing wrong?

Thank you for the advanced.

+5
source share
1 answer

I understood this problem and decided to publish a correction here for this poor soul who will have the same problem somewhere in the future.

I had to change the root, modify the Vehicle class to include the path I wanted, and the @ElementList annotation to return a list of MonitoredVehicleJourney objects.

At the end, the Vehicle class is as follows:

 import org.simpleframework.xml.Element; import org.simpleframework.xml.ElementList; import org.simpleframework.xml.Path; import org.simpleframework.xml.Root; import java.util.List; /** * @author Eduardo Flores */ @Root(name = "Siri", strict=false) public class Vehicle { @Path("VehicleMonitoringDelivery/VehicleActivity") @ElementList(entry = "MonitoredVehicleJourney", inline = true) public List<MonitoredVehicleJourney> monitoredVehicleJourney; public Vehicle(){} } 
+4
source

Source: https://habr.com/ru/post/1241753/


All Articles