我有一个DB输出的列作为xml字符串。我想解析这个xml对象,我可以使用
将其转换为xml字符串 var xmlResponse=new XML(msg['xmlcontent'].toString());
在下一行我希望循环遍历每个节点如果有任何替代方法如何执行此操作请在下面建议使用mirth的xml字符串。
<?xml version="1.0" encoding="utf-8" ?><ORDERMESSAGE><MSH><Sending_Application>HIS</Sending_Application><Sending_Facility>555</Sending_Facility><Receiving_Application>LIS</Receiving_Application><Receiving_Facility/><Message_Date_Time>20160803122348</Message_Date_Time><Security/><Message_Type>ORM</Message_Type><Message_Control_Id/></MSH><ENV><Event_Type_Code>O01</Event_Type_Code><Recorded_DateTime>20160803122348</Recorded_DateTime></ENV><PID><Patient_Id_Ext/><Patient_Id_Int>448</Patient_Id_Int><Patient_Id_Type/><Patient_Id_Number/><Patient_Name>Test Health Check</Patient_Name><Date_Of_Birth>19810802</Date_Of_Birth><Gender_Code>F</Gender_Code><Race_code/><Address1>GUINDY</Address1><Address2/><Address3/><City>Bid</City><State>Maharashtra</State><Postal_Code/><Country_Code>India</Country_Code><Phone_Home/><Phone_Mobile>9764646545</Phone_Mobile><Phone_Business/><Primary_Language/><Marital_Status_Code>Married</Marital_Status_Code><Nationality_Code>Indian</Nationality_Code></PID><PV1><SetIDPatientVisit>574</SetIDPatientVisit><Patient_Type_Code>O</Patient_Type_Code><Ward_Code/><Admission_Type/><Preadmit_Number/><Specialty_Code/><Referring_Doctor_Code/><Referring_Doctor_Desc/><Consulting_Doctor_Code/><Consulting_Doctor_Desc/><Admitting_Doctor_Code/><Admitting_Doctor_Desc/><Patient_Class/><Visit_Number>1146</Visit_Number><Financial_Class_Code/><Admit_DateTime>20160803122003</Admit_DateTime></PV1><ORC><Order_Control>NW</Order_Control><ORC_Placer_Order_Number>544</ORC_Placer_Order_Number><ORC_Filler_Order_Number/><Placer_Group_Number/><Order_Status_Code>Paid</Order_Status_Code><Response_Flag/><ORC_Quantity_Timing>20160803122032</ORC_Quantity_Timing><Parent/><DateTime_Of_Transaction>20160803122032</DateTime_Of_Transaction><Entered_By_ID>9188</Entered_By_ID><Entered_By_Name>Kutti</Entered_By_Name><Verified_By_ID/><Verified_By_Name/><ORC_Ordering_Provider_ID>1</ORC_Ordering_Provider_ID><ORC_Ordering_Provider_Name/><Enter_Location/><Call_Back_Phone_Number/><Order_Effective_DateTime/><Order_Control_Code_Reason/><Entering_Organization/><Entering_Device/><Action_By/><Advanced_Beneficiary_Notice_Code/><Ordering_Facility_Code/><Ordering_Facility_Name/></ORC><OBR><Set_Id_OBR>1</Set_Id_OBR><OBR_Placer_Order_Number>309</OBR_Placer_Order_Number><OBR_Filler_Order_Number/><Package_Code/><Package_Description/><Test_Code/><Test_Name>ABSOLUTE BLAST COUNT</Test_Name><Priority_Code/><Priority_Desc/><Requested_DateTime>20160803122032</Requested_DateTime><Observation_DateTime/><Observation_End_DateTime/><Collection_Volume/><Collector_Identifier/><Specimen_Action_Code/><Danger_Code/><Relevant_Clinical_Info/><Specimen_Received_DateTime/><Specimen_Source_Code/><Specimen_Source_Desc/><OBR_Ordering_Provider_ID>1</OBR_Ordering_Provider_ID><OBR_Ordering_Provider_Name/><Order_Callback_Phone_Number/><Placer_Field1/><Placer_Field2/><Filler_Field1/><Filler_Field2/><Status_Change_DateTime/><Charge_To_Practice/><Diagnostic_Serv_Sect_Code/><Diagnostic_Serv_Sect_Desc/><Result_Status/><Parent_Result/><OBR_Quantity_Timing/><Unit_Code/><Unit_Desc/><Result_Copies_To/><Transportation_Mode/><Reason_For_Study/><Principal_Result_Interpreter/><Assistant_Result_Interpreter/><Technician/><Transcriptionist/><Scheduled_DateTime/><Number_Of_Sample_Containers/><Transport_Logistics_Of_Collected_Sample/><Collector_Comment/><Transport_Arrangement_Responsibility/><Transport_Arranged/><Escort_Required/><Planned_Patient_Transport_Comment/><Procedure_Code/><Procedure_Code_Modifier/><Placer_Supplemental_Service/><Filler_Supplemental_Service/><Cancel_Reason_Code/><Cancel_Reason_Desc/><FeeId>23</FeeId><FeeType>INV</FeeType><MappingId>0</MappingId></OBR></ORDERMESSAGE>
答案 0 :(得分:0)
Mirth Connect使用Rhino作为JavaScript引擎。反过来,JavaScript使用E4X或ECMAScript for XML来简化编写用于处理XML的代码的任务。
所以基本上你的问题有两个部分:
1)要访问或分配数据Feed中的单个字段,您可以使用点表示法,如下所示:
isLoggedIn
2)迭代遍历所有或重复节点,通过选择“消息函数”类别(在任何变换器编辑器的右上角)检查Mirth参考函数,在这里您将看到“迭代过段”或“迭代全部”细分“代码片段,然后拖动并修改它,如下所示:
var eventType = xmlResponse['ENV']['Event_Type_Code'].toString();
但是在你的特殊情况下,就我所知,你没有重复的片段,所以你应该选择第一个选项。