in Education by
I have to unmarshall a XML(XML version 1) to get the values and put these ones in a new version of that XML(XML version 2). The problem is there are a lot of tags with xsi, and this fact is reflected in the unmarshalled class as abstract classes that can be extended by a various classes, and my question is, what is the way to know the class which extends of an abstract class given by the XML xsi:type? I put here my code and the resources, thanks. XML schema that content the data that I want: http://www.datex2.eu/content /xml-schema XML source with data: http://infocar.dgt.es/datex2/dgt/SituationPublication/all/content.xml XML schema of actual version: http://www.datex2.eu/content/datex-ii-xml-schema-23 My finall achieve is to convert the first XML in one of this. My actually code(Testing): public class Main { public static void main(String[] args) throws IOException, SAXException, TransformerException, JAXBException, XMLStreamException, ParserConfigurationException { URL url = null; try { url = new URL("http://infocar.dgt.es/datex2/dgt/SituationPublication/all/content.xml"); } catch (MalformedURLException e) { e.printStackTrace(); } System.out.println("Abriendo URL.."); URLConnection conn = url.openConnection(); System.out.println("URL cargada"); System.out.println("Cargando los datos necesarios..."); JAXBContext jaxbContext = JAXBContext.newInstance(eu.datex.schema._1_0._1_0.D2LogicalModel.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); JAXBElement DatexModelElement = (JAXBElement) unmarshaller.unmarshal(url); eu.datex.schema._1_0._1_0.D2LogicalModel datex1 = DatexModelElement.getValue(); eu.datex2.schema._2_0._2_3.D2LogicalModel datex2 = new eu.datex2.schema._2_0._2_3.D2LogicalModel(); SituationPublication situation = (SituationPublication)datex1.getPayloadPublication(); List situationList = situation.getSituation(); for (int i = 0; i < situationList.size(); ++i) { ListsituationRecordList = situationList.get(i).getSituationRecord(); for(int y = 0; y < situationRecordList.size(); ++y) { //the question is here, how to know which class extends as SituationRecord in other to have one get method or another? } } } } SituationRecord.class example: // // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 // See http://java.sun.com/xml/jaxb // Any modifications to this file will be lost upon recompilation of the source schema. // Generated on: 2010.11.14 at 03:28:36 PM PST // package eu.datex.schema._1_0._1_0; import java.math.BigInteger; import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlID; import javax.xml.bind.annotation.XmlSchemaType; import javax.xml.bind.annotation.XmlSeeAlso; import javax.xml.bind.annotation.XmlType; import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; /** * An identifiable instance of a single record/element within a situation. * *

Java class for SituationRecord complex type. * *

The following schema fragment specifies the expected content contained within this class. * *


 * <complexType name="SituationRecord">

 *   <complexContent>

 *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">

 *       <sequence>

 *         <element name="situationRecordCreationReference" type="{http://datex2.eu/schema/1_0/1_0}String" minOccurs="0"/>

 *         <element name="situationRecordCreationTime" type="{http://datex2.eu/schema/1_0/1_0}DateTime"/>

 *         <element name="situationRecordObservationTime" type="{http://datex2.eu/schema/1_0/1_0}DateTime" minOccurs="0"/>

 *         <element name="situationRecordVersion" type="{http://datex2.eu/schema/1_0/1_0}NonNegativeInteger"/>

 *         <element name="situationRecordVersionTime" type="{http://datex2.eu/schema/1_0/1_0}DateTime"/>

 *         <element name="situationRecordFirstSupplierVersionTime" type="{http://datex2.eu/schema/1_0/1_0}DateTime"/>

 *         <element name="informationUsageOverride" type="{http://datex2.eu/schema/1_0/1_0}InformationUsageEnum" minOccurs="0"/>

 *         <element name="probabilityOfOccurrence" type="{http://datex2.eu/schema/1_0/1_0}ProbabilityOfOccurrenceEnum"/>

 *         <element name="sourceInformation" type="{http://datex2.eu/schema/1_0/1_0}SourceInformation" minOccurs="0"/>

 *         <element name="validity" type="{http://datex2.eu/schema/1_0/1_0}Validity"/>

 *         <element name="impact" type="{http://datex2.eu/schema/1_0/1_0}Impact" minOccurs="0"/>

 *         <element name="cause" type="{http://datex2.eu/schema/1_0/1_0}Cause" minOccurs="0"/>

 *         <element name="advice" type="{http://datex2.eu/schema/1_0/1_0}Advice" maxOccurs="unbounded" minOccurs="0"/>

 *         <element name="generalPublicComment" type="{http://datex2.eu/schema/1_0/1_0}Comment" maxOccurs="unbounded" minOccurs="0"/>

 *         <element name="nonGeneralPublicComment" type="{http://datex2.eu/schema/1_0/1_0}Comment" maxOccurs="unbounded" minOccurs="0"/>

 *         <element name="groupOfLocations" type="{http://datex2.eu/schema/1_0/1_0}GroupOfLocations"/>

 *         <element name="management" type="{http://datex2.eu/schema/1_0/1_0}Management" minOccurs="0"/>

 *         <element name="situationRecordExtension" type="{http://datex2.eu/schema/1_0/1_0}ExtensionType" minOccurs="0"/>

 *       </sequence>

 *       <attribute name="id" use="required" type="{http://www.w3.org/2001/XMLSchema}ID" />

 *     </restriction>

 *   </complexContent>

 * </complexType>

 * 
* * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "SituationRecord", propOrder = { "situationRecordCreationReference", "situationRecordCreationTime", "situationRecordObservationTime", "situationRecordVersion", "situationRecordVersionTime", "situationRecordFirstSupplierVersionTime", "informationUsageOverride", "probabilityOfOccurrence", "sourceInformation", "validity", "impact", "cause", "advice", "generalPublicComment", "nonGeneralPublicComment", "groupOfLocations", "management", "situationRecordExtension" }) @XmlSeeAlso({ NonRoadEventInformation.class, OperatorAction.class, TrafficElement.class }) public abstract class SituationRecord { protected String situationRecordCreationReference; @XmlElement(required = true) protected DateTime situationRecordCreationTime; protected DateTime situationRecordObservationTime; @XmlElement(required = true) protected BigInteger situationRecordVersion; @XmlElement(required = true) protected DateTime situationRecordVersionTime; @XmlElement(required = true) protected DateTime situationRecordFirstSupplierVersionTime; protected InformationUsageEnum informationUsageOverride; @XmlElement(required = true) protected ProbabilityOfOccurrenceEnum probabilityOfOccurrence; protected SourceInformation sourceInformation; @XmlElement(required = true) protected Validity validity; protected Impact impact; protected Cause cause; protected List advice; protected List generalPublicComment; protected List nonGeneralPublicComment; @XmlElement(required = true) protected GroupOfLocations groupOfLocations; protected Management management; protected ExtensionType situationRecordExtension; @XmlAttribute(required = true) @XmlJavaTypeAdapter(CollapsedStringAdapter.class) @XmlID @XmlSchemaType(name = "ID") protected String id; /** * Gets the value of the situationRecordCreationReference property. * * @return * possible object is * {@link String } * */ public String getSituationRecordCreationReference() { return situationRecordCreationReference; } /** * Sets the value of the situationRecordCreationReference property. * * @param value * allowed object is * {@link String } * */ public void setSituationRecordCreationReference(String value) { this.situationRecordCreationReference = value; } /** * Gets the value of the situationRecordCreationTime property. * * @return * possible object is * {@link DateTime } * */ public DateTime getSituationRecordCreationTime() { return situationRecordCreationTime; } /** * Sets the value of the situationRecordCreationTime property. * * @param value * allowed object is * {@link DateTime } * */ public void setSituationRecordCreationTime(DateTime value) { this.situationRecordCreationTime = value; } /** * Gets the value of the situationRecordObservationTime property. * * @return * possible object is * {@link DateTime } * */ public DateTime getSituationRecordObservationTime() { return situationRecordObservationTime; } /** * Sets the value of the situationRecordObservationTime property. * * @param value * allowed object is * {@link DateTime } * */ public void setSituationRecordObservationTime(DateTime value) { this.situationRecordObservationTime = value; } /** * Gets the value of the situationRecordVersion property. * * @return * possible object is * {@link BigInteger } * */ public BigInteger getSituationRecordVersion() { return situationRecordVersion; } /** * Sets the value of the situationRecordVersion property. * * @param value * allowed object is * {@link BigInteger } * */ public void setSituationRecordVersion(BigInteger value) { this.situationRecordVersion = value; } /** * Gets the value of the situationRecordVersionTime property. * * @return * possible object is * {@link DateTime } * */ public DateTime getSituationRecordVersionTime() { return situationRecordVersionTime; } /** * Sets the value of the situationRecordVersionTime property. * * @param value * allowed object is * {@link DateTime } * */ public void setSituationRecordVersionTime(DateTime value) { this.situationRecordVersionTime = value; } /** * Gets the value of the situationRecordFirstSupplierVersionTime property. * * @return * possible object is * {@link DateTime } * */ public DateTime getSituationRecordFirstSupplierVersionTime() { return situationRecordFirstSupplierVersionTime; } /** * Sets the value of the situationRecordFirstSupplierVersionTime property. * * @param value * allowed object is * {@link DateTime } * */ public void setSituationRecordFirstSupplierVersionTime(DateTime value) { this.situationRecordFirstSupplierVersionTime = value; } /** * Gets the value of the informationUsageOverride property. * * @return * possible object is * {@link InformationUsageEnum } * */ public InformationUsageEnum getInformationUsageOverride() { return informationUsageOverride; } /** * Sets the value of the informationUsageOverride property. * * @param value * allowed object is * {@link InformationUsageEnum } * */ public void setInformationUsageOverride(InformationUsageEnum value) { this.informationUsageOverride = value; } /** * Gets the value of the probabilityOfOccurrence property. * * @return * possible object is * {@link ProbabilityOfOccurrenceEnum } * */ public ProbabilityOfOccurrenceEnum getProbabilityOfOccurrence() { return probabilityOfOccurrence; } /** * Sets the value of the probabilityOfOccurrence property. * * @param value * allowed object is * {@link ProbabilityOfOccurrenceEnum } * */ public void setProbabilityOfOccurrence(ProbabilityOfOccurrenceEnum value) { this.probabilityOfOccurrence = value; } /** * Gets the value of the sourceInformation property. * * @return * possible object is * {@link SourceInformation } * */ public SourceInformation getSourceInformation() { return sourceInformation; } /** * Sets the value of the sourceInformation property. * * @param value * allowed object is * {@link SourceInformation } * */ public void setSourceInformation(SourceInformation value) { this.sourceInformation = value; } /** * Gets the value of the validity property. * * @return * possible object is * {@link Validity } * */ public Validity getValidity() { return validity; } /** * Sets the value of the validity property. * * @param value * allowed object is * {@link Validity } * */ public void setValidity(Validity value) { this.validity = value; } /** * Gets the value of the impact property. * * @return * possible object is * {@link Impact } * */ public Impact getImpact() { return impact; } /** * Sets the value of the impact property. * * @param value * allowed object is * {@link Impact } * */ public void setImpact(Impact value) { this.impact = value; } /** * Gets the value of the cause property. * * @return * possible object is * {@link Cause } * */ public Cause getCause() { return cause; } /** * Sets the value of the cause property. * * @param value * allowed object is * {@link Cause } * */ public void setCause(Cause value) { this.cause = value; } /** * Gets the value of the advice property. * *

* This accessor method returns a reference to the live list, * not a snapshot. Therefore any modification you make to the * returned list will be present inside the JAXB object. * This is why there is not a set method for the advice property. * *

* For example, to add a new item, do as follows: *


     *    getAdvice().add(newItem);

     * 
* * *

* Objects of the following type(s) are allowed in the list * {@link Advice } * * */ public List getAdvice() { if (advice == null) { advice = new ArrayList(); } return this.advice; } /** * Gets the value of the generalPublicComment property. * *

* This accessor method returns a reference to the live list, * not a snapshot. Therefore any modification you make to the * returned list will be present inside the JAXB object. * This is why there is not a set method for the generalPublicComment property. * *

* For example, to add a new item, do as follows: *


     *    getGeneralPublicComment().add(newItem);

     * 
* * *

* Objects of the following type(s) are allowed in the list * {@link CommentStructure.Comment } * * */ public List getGeneralPublicComment() { if (generalPublicComment == null) { generalPublicComment = new ArrayList(); } return this.generalPublicComment; } /** * Gets the value of the nonGeneralPublicComment property. * *

* This accessor method returns a reference to the live list, * not a snapshot. Therefore any modification you make to the * returned list will be present inside the JAXB object. * This is why there is not a set method for the nonGeneralPublicComment property. * *

* For example, to add a new item, do as follows: *


     *    getNonGeneralPublicComment().add(newItem);

     * 
* * *

* Objects of the following type(s) are allowed in the list * {@link CommentStructure.Comment } * * */ public List getNonGeneralPublicComment() { if (nonGeneralPublicComment == null) { nonGeneralPublicComment = new ArrayList(); } return this.nonGeneralPublicComment; } /** * Gets the value of the groupOfLocations property. * * @return * possible object is * {@link GroupOfLocations } * */ public GroupOfLocations getGroupOfLocations() { return groupOfLocations; } /** * Sets the value of the groupOfLocations property. * * @param value * allowed object is * {@link GroupOfLocations } * */ public void setGroupOfLocations(GroupOfLocations value) { this.groupOfLocations = value; } /** * Gets the value of the management property. * * @return * possible object is * {@link Management } * */ public Management getManagement() { return management; } /** * Sets the value of the management property. * * @param value * allowed object is * {@link Management } * */ public void setManagement(Management value) { this.management = value; } /** * Gets the value of the situationRecordExtension property. * * @return * possible object is * {@link ExtensionType } * */ public ExtensionType getSituationRecordExtension() { return situationRecordExtension; } /** * Sets the value of the situationRecordExtension property. * * @param value * allowed object is * {@link ExtensionType } * */ public void setSituationRecordExtension(ExtensionType value) { this.situationRecordExtension = value; } /** * Gets the value of the id property. * * @return * possible object is * {@link String } * */ public String getId() { return id; } /** * Sets the value of the id property. * * @param value * allowed object is * {@link String } * */ public void setId(String value) { this.id = value; } } JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
JAXB is able to implement the class given by the XML xsi automatically. situationRecord.getClass().toString() The above line gives me the name of the class which extends of situationRecord.class

Related questions

0 votes
    I have a generic method which a generic type parameter T which is a subclass of MyClass. Inside that method, I want ... of type erasure): object Demo extends App { def myMethod[T...
asked Jun 30, 2022 in Education by JackTerrance
0 votes
    Q: I allow my user to upload an xml file to insert its contents in my database. I ask if there' ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    Q: I allow my user to upload an xml file to insert its contents in my database. I ask if there' ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    Q: I allow my user to upload an xml file to insert its contents in my database. I ask if there' ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    Can an abstract class have a constructor?...
asked Feb 9, 2023 in Technology by JackTerrance
0 votes
    What is the difference between an abstract class and an interface?...
asked Feb 9, 2023 in Technology by JackTerrance
0 votes
    I have an abstract class Product public abstract class Product implements Serializable { private Integer id; private ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    Which of these can be used to fully abstract a class from its implementation? (a) Objects (b) Packages (c) ... & Packages of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    What Is An Abstract Class And What Is It’s Purpose? Select the correct answer from above options...
asked Dec 24, 2021 in Education by JackTerrance
0 votes
    Abstract class cannot have a constructor. (a) True (b) False I have been asked this question in ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 26, 2021 in Education by JackTerrance
0 votes
    Which of these keywords are used to define an abstract class? (a) abst (b) abstract (c) Abstract ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    If a class inheriting an abstract class does not define all of its function then it will be known as ... questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
0 votes
    What is the difference between abstract class and interface in C#?...
asked Jul 27, 2021 in Technology by JackTerrance
...