0

我的 xml 看起来像

- <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> 

完整的 xml 在这里http://www.speedyshare.com/MgCCA/download/ItemMaster-2.xml

我需要使用属性 TYPE = "BRAND" 获取分类的值,但使用下面的代码,它只获取具有属性 TYPE = "HOMOLOGATION CLASS" 的分类,因为我正在调用 "BRAND",所以我不想要它。我尝试应用 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.
4

2 回答 2

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;
于 2013-05-10T10:04:53.237 回答
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”生成一个“行”文件夹,在每个“product_Info”文件夹中放置一个“product_Info”文件夹,在该文件夹中放置(属性)“类型”=“品牌”的“分类”中的代码。

希望这可以帮助。问候,

于 2013-05-11T19:06:27.723 回答