I have a situation to parse an XML which is having much data in attributes and levels to access the data inside the XML hierarchy.
Confused about which parser to be used for this to be a effective approach for parsing. Parsing the XML and how to access the attributes & its value.
I was preferring DOM parser and trying to parse it but it was a little complex as i needed to get a tag -> then an attribute -> then attr value and on that condition need to get another tag access.
<testCodeIdentifier classCode="ROL" >
<realmCode code="QD" />
<id assigningAuthorityName="PRMKEY" extension="SJC16494" />
<statusCode code="active" />
<playingTestCodeDetails classCode="ENT" determinerCode="INSTANCE" >
<realmCode code="QD" />
<id assigningAuthorityName="PRMORDCODE" extension="16494" />
<id assigningAuthorityName="TESTNUMINBOOK" extension="16494" />
<code code="16494" codeSystemName="QTIM" displayName="SureSwab Candidiasis" />
<name use=""></name>
<asSeeAlsoCode classCode="ROL" >
<realmCode code="QD" />
<code code="7600" displayName="Sample See Also Name" ></code>
</asSeeAlsoCode>
<asSeeAlsoCode classCode="ROL" >
<realmCode code="QD" />
<code code="6496" displayName="Sample See Also Name" ></code>
</asSeeAlsoCode>
</playingTestCodeDetails>
</testCodeIdentifier>
Above is the sample XML in which all attributes are present as data i need to traverse them… JAXB..how can we use it????
IF the size of the XML file isn’t going to be huge, you can look at following options:
JAXB (If you have a schema definition, it will generate the objects and auto populate for you).
JiBX (Another good alternative. You can define custom mapping of XML attributes to Java Objects)
XStream (Also allows you to map XML attributes to Java Objects).