<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" > <!-- Have repeated Seealsocode section for multiple see also codes and stripped names -->
<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>
<subjectOf typeCode="SBJ">
<realmCode code="QD" />
<order classCode="OBS" moodCode="EVN" >
<realmCode code="QD" />
<performer nullFlavor="" typeCode="PRF"><!-- Have added this to accomodate the UnitCode-->
<performingLocatedEntity classCode="LOCE" nullFlavor="">
<locatedPerformingSite classCode="ORG" determinerCode="INSTANCE">
<id assigningAuthorityName="ASORDERED" extension="16494" />
</locatedPerformingSite>
</performingLocatedEntity>
</performer>
<origin nullFlavor="" typeCode="ORG"> <!-- Have added this to accomodate the Ordering Lab Code-->
<orderingLocatedEntity classCode="LOCE" >
<locatedOrderingSite classCode="ORG" determinerCode="INSTANCE">
<id assigningAuthorityName="PRMORDCODE" extension="16494"/>
<code code="SJC" codeSystemName="QTIM" codeSystem="ORDERINGLABCODE"/>
</locatedOrderingSite>
</orderingLocatedEntity>
</origin>
<pertinentInformation1 typeCode="PERT">
<realmCode code="QD" />
<clinicalInfo classCode="ACT" moodCode="EVN">
<realmCode code="QD" />
<title>Specialitysample1</title>
<text>Conditionsample1</text>
</clinicalInfo>
</pertinentInformation1>
<subjectOf typeCode="SUBJ">
<realmCode code="QD" />
<annotation classCode="ACT" moodCode="EVN" >
<realmCode code="QD" />
<code code="DOSCATNAME"></code>
<text><![CDATA[SureSwab<sup>®</sup>, <em>Candidiasis</em>, PCR]]></text>
</annotation>
</subjectOf>
</subjectOf>
我有一个像上面这样的 xml。我想解析它;解析它的最佳方法是什么? DOM、SAX(我听说过 JAXB、XSLT,...不确定这两个);我们可以结合使用 DOM 和 SAX 来解析 XML吗?
使用属性访问作为“代码”来获取标签值的简单场景 就像当标签中的code=DOSCATNAME时,我们需要为相应的标签获取数据。
另一种场景是访问标签并获取层次结构,并在分配AuthorityName属性值为PRMORDCODE时访问扩展属性。
使用解析器可以实现上述两种情况吗?
我是新手,请理解我需要解析的内容并建议我一个想法...提前致谢...
最佳答案
使用 JAXB。创建类模型并适本地注释您的类。环境将完成剩下的工作。
例如,您应该创建类 PlayingTestCodeDetails
,其属性为 classCode
、determinerCode
等。
我会告诉您更多信息:您可以要求 JAXB 为您生成类。从这篇文章开始学习:http://www.roseindia.net/jaxb/r/jaxb.shtml
开始需要几个小时,但 15 分钟内即可完成。如果您使用 DOM,您可以在 15 分钟内开始学习,并在几天内编写代码来解析您的 XML。
关于java - XML 解析 - DOM 或 SAX - 以属性作为访问 java 层次结构的条件的复杂 xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8558616/