1. 程式人生 > 其它 >xml檔案解析

xml檔案解析

技術標籤:java

public final static Map<String, String> analysisPatientRegistryAddRequestMessage(String message) {
	Map<String, String> mapValue = new HashMap<String, String>();
		if (StringUtils.isEmpty(message)) {
			return mapValue;
		}
	//將xml檔案解析成Document物件
	Document doc=DocumentHelper.
parseText(message); //獲取xml文件的根標籤 Element root=doc.getRootElement();\ //獲取根標籤下的第一個id標籤 Element id=root.element("id"); //獲取extension屬性值 Attribute id_extension=id.attribute("extension"); String id_val=id_extension.getStringValue(); mapValue.put("_id",id_val); //獲取creationTime=root.element("creationTime”);
Element creationTime=Root.element("creationTime"); Attribute cv=creationTime.attribute("value"); String cv_value=getStringValue("value"); //獲取根標籤下的第一個controlActProcess標籤 Element controlActProcess = root.element("controlActProcess"); //獲取controlActProcess標籤下的第一個subject標籤
Element subject = controlActProcess.element("subject"); Element registrationRequest = subject.element("registrationRequest"); Element subject1 = registrationRequest.element("subject1"); Element patient = subject1.element("patient"); // sourceId Element sourceId = patient.element("id"); if (sourceId != null) { Attribute sourceId_extension = sourceId.attribute("extension"); String se_value = sourceId_extension.getStringValue(); mapValue.put("SOURCE_ID", se_value); } }