0

I know there's a lot of content around here about it, but I'm not being able to accomplish a especific struture:

<ECG
ACQUISITION_TIME="20190625101706"
ACQUISITION_TIME_XML="2019-06-25T10:17:06"
ROOM=""
LOCATION="AMB"
COMMENT="ANDRESA"
AGE="45"
AGE_UNITS="Y"
HEIGHT="164"
HEIGHT_UNITS="C"
WEIGHT="85"
WEIGHT_UNITS="K"
NUM_QRS="10"
AVERAGE_RR="1013"
VENT_RATE="59"
TECHNICIAN=""
SYSTOLIC_BP="000"
DIASTOLIC_BP="000"
SEQUENCE_NUMBER="17617">

<DEMOGRAPHIC_FIELDS>
<DEMOGRAPHIC_FIELD ID="2" LABEL="Solic.:" VALUE="172001" UNITS="" />
<DEMOGRAPHIC_FIELD ID="7" LABEL="Nome:" VALUE="PAC TEST2" UNITS="" />
<DEMOGRAPHIC_FIELD ID="1" LABEL="Sobre:" VALUE="SOBROME2" UNITS="" />
<DEMOGRAPHIC_FIELD ID="26" LABEL="Prontuário" VALUE="SMO" UNITS="" />
<DEMOGRAPHIC_FIELD ID="4" LABEL="Sexo:" VALUE="Female" UNITS="" />
<DEMOGRAPHIC_FIELD ID="3" LABEL="" VALUE="45" UNITS="Y" />
<DEMOGRAPHIC_FIELD ID="9" LABEL="Alt:" VALUE="164" UNITS="C" />
<DEMOGRAPHIC_FIELD ID="10" LABEL="Peso:" VALUE="85" UNITS="K" />
<DEMOGRAPHIC_FIELD ID="14" LABEL="Local:" VALUE="AMB" UNITS="" />
<DEMOGRAPHIC_FIELD ID="17" LABEL="Obs.:" VALUE="ANDRESA" UNITS="" />
</DEMOGRAPHIC_FIELDS>

<SITE ID="1"/>

<SUBJECT
LAST_NAME="SOBRENOME2"
FIRST_NAME="PACIENTE TESTE2"
GENDER="Female"
ID="11402872001"
DOB="00000000"
DOB_XML="0000-00-00"/>

</ECG>

This is a part of xml file I need to convert, I'm really confused about what should be an element, an attribute or and object

@XmlRootElement(name = "ECG")
@XmlAccessorType(XmlAccessType.FIELD)
public class MortaraXml implements Serializable {

  @XmlElement(name = "DEMOGRAPHIC_FIELDS")
  private List<MortaraXmlDemographicField> demographicField;

  @XmlElement(name = "SITE")
  private String site;

  @XmlElement(name = "SUBJECT")
  private String subject;
}

@XmlRootElement(name = "DEMOGRAPHIC_FIELD")
@XmlAccessorType(XmlAccessType.FIELD)
public class MortaraXmlDemographicField implements Serializable {

  @XmlAttribute(name = "ID")
  private String id;

  @XmlAttribute(name = "LABEL")
  private String label;

  @XmlAttribute(name = "VALUE")
  private String value;

  @XmlAttribute(name = "UNITS")
  private String units;
}

This was how I started my code, but I'm pretty confused on how to structure this properly. How to handle tags with no data but only attributes? And tags that contains a list of the same tag? Is there some example similiar to what I need? Thanks for any help!

1 Answers1

2

Ideally you should have a xsd schema for this XML. If not create one for this XML. And then using that xsd schema you can generate java class using xjc utility from java from command line.