2016-09-30 107 views
0

我想用XPath編寫一個表達式,用於將我xml消息頭中的屬性值與特定值進行比較,以將其指向適當的文件夾。 XML頭是用於比較駱駝屬性值的表達式Java DSL

?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet type="text/xsl" href="cda\render\cda.xsl"?> 
    <Books xmlns="urn:hl7-org:v3" 
     xmlns:classCode="DOCCLIN" xmlns:moodCode="EVN" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="urn:hl7-org:v3 ./cda_r2_normativewebedition2010/infrastructure/cda/CDA.xsd"> 
     <realmCode code="DE" /> 
     <typeId root="2.16.840.1.113883.1.3" extension="POCD_HD000040" /> 
     <templateId root="2.16.840.1.113883.10.20.29" /> 
     <templateId root="2.16.840.1.113883.10.20.33" /> 
     <templateId root="2.16.840.1.113883.10.20.33.1.1" /> 
     <id extension="2015121415313522" /> 
     <code code="12.3.34.65" codeSystem="2.16.840.1.113883.6.1" 
      codeSystemName="LOINC" displayName="Document" /> 
     <title>Prices</title> 
     <effectiveTime value="201512141531+0000" /> 
     <confidentialityCode code="N" codeSystem="2.16.840.1.113883.5.25" /> 
     <languageCode code="de-DE" /> 

我想比較某一節點attirbute(屬性碼元的代碼)的值並將其引導到保持真正的文件夾它。

我寫的東西像

from("file:testxml/") 
       .choice() 
       .when() 
//    .xpath("urn:hl7-org:v3:Books/urn:hl7-org:v3:code/@code = '12.3.34.65'") 
       .xpath("urn:hl7-org:v3:ClinicalDocument/urn:hl7-org:v3:code[@code='12.3.34.65']") 
       .to("file:xPath/") 
       .to("direct:xpath"); 

      } 

我要檢查的屬性的值是否是'12 .3.34.65' 。請你糾正我,讓我知道如何以正確的方式寫xpath表達式。

非常感謝!

回答

0

您的示例x​​ml無效。代碼元素的屬性代碼也不是'12.3.34.65'。請嘗試在下面將輸出重定向到destinationFolder。

from("file:testxml") 
.choice() 
    .when() 
    .xpath("/Books/code[@code='x.x.x.x']") 
    .to("file:destinationFolder"); 
+0

你是對的屬性值,但我錯誤地粘貼了抽象值。我現在糾正了它。我使用值'12.3.3.6.6'測試了XML。你寫的代碼和我寫的代碼一樣,但沒有名字空間。如果沒有名稱空間參考,表達式將不起作用。 – Lucky