2013-05-10 77 views
0

我的XML看起來像LASTMOVE循環不工作

- <ItemMaster> 
    - <ItemMasterHeader> 
     + <ItemID> 
     + <ItemStatus> 
     + <UserArea> 
     - <Classification Type="HOMOLOGATION CLASS"> 
      - <Codes> 
      <Code>E</Code> 
      </Codes> 
     </Classification> 
     + <Classification Type="LP"> 
     + <Classification> 
     - <Classification Type="BRAND"> 
      - <Codes> 
       <Code>002</Code> 
      </Codes> 
     </Classification> 

YHE完整的XML是在這裏http://www.speedyshare.com/MgCCA/download/ItemMaster-2.xml

我需要獲取分類與屬性TYPE =「品牌」的價值,但與下面的代碼,它只取得屬性TYPE =「HOMOLOGATION CLASS」的分類,我不想要,因爲我要求「品牌」。我試圖申請LASTMOVE,但劑量的工作。請告訴我我錯在哪裏。

我必須獲取其他值也類似代碼裏面的類型 - 「LP」也。

DECLARE rResource REFERENCE TO InputRoot.XMLNSC.*:SyncItemMaster.*:DataArea.*:ItemMaster.*:ItemMasterHeader[1]; 
     SET rowCnt = rowCnt+1;  
     DECLARE LineCount INTEGER 1; 

     WHILE LASTMOVE(rResource) = TRUE DO  
     SET OutputRoot.XMLNSC.root.row[rowCnt].product_Info.TyreBrandCd = THE (SELECT ITEM FIELDVALUE(T) FROM itemMaster.*:ItemMasterHeader[LineCount].*:Classification.*:Codes.*:Code AS T WHERE FIELDVALUE(itemMaster.*:ItemMasterHeader[LineCount].*:Classification.(XMLNSC.Attribute)Type) = 'BRAND'); 
      SET LineCount = LineCount + 1; 
     MOVE rResource NEXTSIBLING REPEAT TYPE NAME; 
     END WHILE;    
    RETURN TRUE; 
    END; 

感謝

下面受審的推薦代碼:

下面是跟蹤日誌

2013-05-10 18:32:27.218385 7732 UserTrace BIP2537I: Node 'WMB_9D1_PROD_SUB00_001.9D1_PROD': Executing statement ''SET temp = THE (SELECT T.Classification AS :Classification FROM myref AS T WHERE FIELDVALUE(T.Classification.(XMLNSC.Attribute)Type) = 'BRAND');'' at ('.WMB_9D1_PROD_SUB00_001.Main', '22.3'). 
2013-05-10 18:32:27.218393 7732 UserTrace BIP2538I: Node 'WMB_9D1_PROD_SUB00_001.9D1_PROD': Evaluating expression ''THE (SELECT T.Classification AS :Classification FROM myref AS T WHERE FIELDVALUE(T.Classification.(XMLNSC.Attribute)Type) = 'BRAND')'' at ('.WMB_9D1_PROD_SUB00_001.Main', '22.14'). 
2013-05-10 18:32:27.218400 7732 UserTrace BIP2572W: Node: 'WMB_9D1_PROD_SUB00_001.9D1_PROD': ('.WMB_9D1_PROD_SUB00_001.Main', '22.14') : Finding one and only SELECT result. 
2013-05-10 18:32:27.218427 7732 UserTrace BIP2539I: Node 'WMB_9D1_PROD_SUB00_001.9D1_PROD': Evaluating expression ''myref'' at ('.WMB_9D1_PROD_SUB00_001.Main', '22.48'). This resolved to ''myref''. The result was ''ROW... Root Element Type=16777216 NameSpace='' Name='ItemMasterHeader' Value=NULL''. 
2013-05-10 18:32:27.218437 7732 UserTrace BIP2539I: Node 'WMB_9D1_PROD_SUB00_001.9D1_PROD': Evaluating expression ''XMLNSC.Attribute'' at ('.WMB_9D1_PROD_SUB00_001.Main', '22.94'). This resolved to ''XMLNSC.Attribute''. The result was ''1095266992384''. 
2013-05-10 18:32:27.218446 7732 UserTrace BIP2540I: Node 'WMB_9D1_PROD_SUB00_001.9D1_PROD': Finished evaluating expression ''FIELDVALUE(T.Classification.(XMLNSC.Attribute)Type)'' at ('.WMB_9D1_PROD_SUB00_001.Main', '22.65'). The result was '''HOMOLOGATION CLASS'''. 
2013-05-10 18:32:27.218454 7732 UserTrace BIP2539I: Node 'WMB_9D1_PROD_SUB00_001.9D1_PROD': Evaluating expression ''FIELDVALUE(T.Classification.(XMLNSC.Attribute)Type) = 'BRAND''' at ('.WMB_9D1_PROD_SUB00_001.Main', '22.117'). This resolved to '''HOMOLOGATION CLASS' = 'BRAND'''. The result was ''FALSE''. 
2013-05-10 18:32:27.218461 7732 UserTrace BIP2569W: Node 'WMB_9D1_PROD_SUB00_001.9D1_PROD': ('.WMB_9D1_PROD_SUB00_001.Main', '22.14') : WHERE clause evaluated to false or unknown. Iterating FROM clause. 
2013-05-10 18:32:27.218469 7732 UserTrace BIP2570W: Node 'WMB_9D1_PROD_SUB00_001.9D1_PROD': ('.WMB_9D1_PROD_SUB00_001.Main', '22.14') : There were no items in the FROM clause satisfying the WHERE clause. 
2013-05-10 18:32:27.218503 7732 UserTrace BIP2567I: Node 'WMB_9D1_PROD_SUB00_001.9D1_PROD': Assigning NULL to ''temp'', thus deleting it. 

回答

1

試試這個:

declare temp ROW; 

SET temp = THE (SELECT T.Classification FROM rResource AS T WHERE FIELDVALUE(T.Classification.(XMLNSC.Attribute)Type) = 'BRAND'); 

OutputRoot.XMLNSC.root.row[rowCnt].product_Info.TyreBrandCd = temp.code; 
+0

我會測試,讓你知道 – Yogus 2013-05-10 10:24:17

+0

Didnt工作:( – Yogus 2013-05-10 10:34:57

0

我不知道你在找什麼樣的地圖。假設你想要的是'代碼',在每個'ItemMasterHeader'上具有正確屬性的'分類'中,出現在單獨'行'文件夾內的輸出中,這裏是代碼:

CREATE PROCEDURE ExtractTyreCodes() BEGIN 
     DECLARE rOutput REFERENCE TO OutputRoot; 
     DECLARE rResource REFERENCE TO InputRoot.XMLNSC.*:SyncItemMaster.*:DataArea.*:ItemMaster; 
     CREATE FIELD OutputRoot.XMLNSC.root AS rOutput; 
     IF LASTMOVE(rResource) THEN 
     SET rOutput.row[] = SELECT 
       THE(SELECT C.*:Codes.*:Code AS TyreBrand 
        FROM T.*:Classification[] AS C 
        WHERE C.(XMLNSC.Attribute)Type = 'BRAND') AS product_Info 
       FROM rResource.*:ItemMasterHeader[] AS T; 
     END IF; 
END; 

從這個消息開始:

<SyncItemMaster> 
    <DataArea> 
    <ItemMaster> 
     <ItemMasterHeader> 
     <ItemID/> 
     <ItemStatus/> 
     <UserArea/> 
     <Classification Type="HOMOLOGATION CLASS"> 
      <Codes> 
      <Code>E</Code> 
      </Codes> 
     </Classification> 
     <Classification Type="LP"/> 
     <Classification/> 
     <Classification Type="BRAND"> 
      <Codes> 
      <Code>002</Code> 
      </Codes> 
     </Classification> 
     </ItemMasterHeader> 
     <ItemMasterHeader> 
     <ItemID/> 
     <ItemStatus/> 
     <UserArea/> 
     <Classification Type="HOMOLOGATION CLASS"> 
      <Codes> 
      <Code>F</Code> 
      </Codes> 
     </Classification> 
     <Classification Type="LP"/> 
     <Classification/> 
     <Classification Type="BRAND"> 
      <Codes> 
      <Code>005</Code> 
      </Codes> 
     </Classification> 
     </ItemMasterHeader> 
    </ItemMaster> 
    </DataArea> 
</SyncItemMaster> 

你得到這個消息:

<root> 
    <row> 
    <product_Info> 
     <TyreBrand>002</TyreBrand> 
    </product_Info> 
    </row> 
    <row> 
    <product_Info> 
     <TyreBrand>005</TyreBrand> 
    </product_Info> 
    </row> 
</root> 

這會產生一個 '行' 文件夾的每個 'ItemMasterHeader',把每一個 '產品的詳細信息' F的內部年齡較大,並且在其中放置來自(屬性)'類型'的'分類'='品牌'的代碼。

希望這會有所幫助。問候,

+0

@謝林謝謝我看到,但如果我需要在輸出中也有其他值的樹也像我需要取其他品牌也應該也進來insode the product_info標籤 我已經引用了xml鏈接 – Yogus 2013-05-11 23:58:54

+0

@Deonia您提供的XML似乎有嚴重的結構問題,它有一個重複的元素Classification/@ Type =「BRAND」,其中兩個實例具有不同的結構和內容。因此,當您通過該屬性值(「品牌」)進行過濾時,您無法確定該元素是否包含代碼或其他任何內容,因此,我建議您使用以下兩種方法之一: 1.要使用自定義REPEAT循環,用CASE語句從每個標記中提取所需的信息。 2.使用代碼提取收集具有給定過濾器的所有元素(使結構扁平化)。 – Shrein 2013-05-13 17:40:59

+0

是的,我知道。 XMl狀態不佳:( – Yogus 2013-05-13 17:42:23