2013-05-10 79 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