XPath使用从XML获取数据-Pentaho

问题描述 投票:0回答:1

我正在调用Xero的API,然后使用从XML获取数据步骤。如何提取折旧费用-218.8?我试过/ Rows / Row / Cells / Cell / Attributes /。和“行/行/单元格/单元格/值”等选项,但它们不起作用。另一个问题是,如果我有多个帐户,并且需要准确提取“折旧费用”,我曾尝试使用[]提取第N个元素,但是某种程度上它不起作用。是Pentaho的细节吗?

          <RowType>Section</RowType>
          <Title>Less Operating Expenses</Title>
          <Rows>
            <Row>
              <RowType>Row</RowType>
              <Cells>
                <Cell>
                  <Value>Depreciation Expense</Value>
                  <Attributes>
                    <Attribute>
                      <Value>f14d778f842543feafca2fdcf0437cf7</Value>
                      <Id>account</Id>
                    </Attribute>
                    <Attribute>
                      <Value>f14d778f842543feafca2fdcf0437cf7</Value>
                      <Id>groupID</Id>
                    </Attribute>
                  </Attributes>
                </Cell>
                <Cell>
                  <Value>218.16</Value>
                  <Attributes>
                    <Attribute>
                      <Value>f14d778f842543feafca2fdcf0437cf7</Value>
                      <Id>account</Id>
                    </Attribute>
                    <Attribute>
                      <Value>f14d778f842543feafca2fdcf0437cf7</Value>
                      <Id>groupID</Id>
                    </Attribute>
                  </Attributes>
                </Cell>
              </Cells>
            </Row>
pentaho pdi
1个回答
0
投票

对于像这样的复杂XML结构,通常最好在Pentaho中使用嵌套的从XML获取数据步骤。

XML的第一步应将每个XML行提取到Pentaho行中。为此,可以使用Loop XPath设置/ YourRoot / Rows / Row并获得带有XPath“单元”和结果类型“单节点”的字段。包括rownum字段可能很好,如果需要,请选择该选项。

然后,第二个XML步骤可以使用第一步中的输出字段,从Loop XPath / Cells / Cell中提取并使用“获取字段”按钮获取所有字段。

一旦有了字段,请使用“选择值”步骤删除原始XML字段,然后使用Row Denormalizer(困难但健壮)或Row Flattener(简单但仅适用于固定单元格顺序)。

© www.soinside.com 2019 - 2024. All rights reserved.