您不需要解析 Text 元素。CCDA 文档中的文本元素用于使其成为人类可读的格式。相同的值也将出现在部分的条目元素中。
编辑:以下代码可能会有所帮助
package org.openhealthtools.mdht.uml.cda.consol.tests;
import java.io.FileInputStream;
import java.util.Stack;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.util.FeatureMap;
import org.eclipse.emf.ecore.util.FeatureMap.Entry;
import org.eclipse.emf.ecore.xml.type.AnyType;
import org.openhealthtools.mdht.uml.cda.ClinicalDocument;
import org.openhealthtools.mdht.uml.cda.StrucDocText;
import org.openhealthtools.mdht.uml.cda.consol.AllergiesSection;
import org.openhealthtools.mdht.uml.cda.consol.ConsolPackage;
import org.openhealthtools.mdht.uml.cda.consol.ContinuityOfCareDocument;
import org.openhealthtools.mdht.uml.cda.util.CDAUtil;
import org.openhealthtools.mdht.uml.cda.util.ValidationResult;
public class Main {
public static void main(String[] args) throws Exception {
ConsolPackage.eINSTANCE.eClass(); // static package registration
ClinicalDocument clinicalDocument = CDAUtil.load(
new FileInputStream("samples/CCD.sample.xml"), (ValidationResult) null);
if (clinicalDocument instanceof ContinuityOfCareDocument) {
ContinuityOfCareDocument ccd = (ContinuityOfCareDocument) clinicalDocument;
AllergiesSection allergiesSection = ccd.getAllergiesSection();
StrucDocText text = allergiesSection.getText();
traverse(text.getMixed());
}
}
private static void traverse(FeatureMap root) {
Stack<FeatureMap> stack = new Stack<FeatureMap>();
stack.push(root);
while (!stack.isEmpty()) {
FeatureMap featureMap = stack.pop();
for (int i = featureMap.size() - 1; i >= 0; i--) {
Entry entry = featureMap.get(i);
if (entry.getEStructuralFeature() instanceof EReference) {
System.out.println(entry.getEStructuralFeature().getName() + " {");
AnyType anyType = (AnyType) entry.getValue();
traverseAttributes(anyType.getAnyAttribute());
stack.push(anyType.getMixed());
} else {
if (entry.getValue() != null) {
String value = entry.getValue().toString();
if (value.trim().length() > 0) {
System.out.println(" " + value + " }");
}
} else {
System.out.println(" }");
}
}
}
}
}
private static void traverseAttributes(FeatureMap anyAttribute) {
for (Entry entry : anyAttribute) {
System.out.println("attr name: " + entry.getEStructuralFeature().getName() + ", attr value: " +
entry.getValue().toString());
}
}
}
// 此代码的控制台输出为:
table {
attr name: border, attr value: 1
attr name: width, attr value: 100%
tbody {
thead {
tr {
th {
th {
th {
Substance }
Reaction }
Status }
tr {
tr {
tr {
td {
td {
td {
Penicillin }
content {
attr name: ID, attr value: reaction1
Hives }
Active }
td {
td {
td {
Aspirin }
content {
attr name: ID, attr value: reaction2
Wheezing }
Active }
td {
td {
td {
Codeine }
content {
attr name: ID, attr value: reaction3
Nausea }
Active }
参考:链接