使用 Get data from XML 的 XPath - Pentaho
XPath using Get data from XML - Pentaho
我正在调用 Xero 的 API,然后使用从 XML 步骤获取数据。如何提取折旧费用 - 218.8?我试过 /Rows/Row/Cells/Cell/Attributes/。和 Rows/Row/Cells/Cell/Value - 以及其他选项,但它们没有用。另一个问题是,如果我有多个帐户并且我需要准确地提取 'Depreciation Expense',我尝试使用 [] 来提取第 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>
对于像这样的复杂 XML 结构,通常最好使用嵌套 从 Pentaho 中的 XML 步骤获取数据。
在您的示例中(缺少根元素并关闭 /rows btw)它看起来像 XML 代表一个 Excel-like "rows with cells" 结构。这些单元格可能属于一列,具体取决于它们的顺序。对于这个答案,我假设这个顺序确实在 XML 中固定并且没有丢失的单元格。验证!
第一个 XML 步骤应该将每个 XML "row" 提取到 Pentaho 行中并返回 XML 节点,而不仅仅是一个值。为此,您可以使用 Loop XPath 设置 /YourRoot/Rows/Row 并获得带有 XPath "Cells" 和 [=23 的字段=]结果类型"Single node"。包含一个 rownum 字段可能会很好,select 如果需要,该选项。
然后第二个 XML 步骤可以使用第一个步骤的输出字段,从 Loop XPath /Cells/Cell 中提取并获取您需要使用的所有字段“获取字段”按钮。
获得字段后,使用 Select 值步骤删除原始 XML 字段,然后使用 Row Flattener(仅适用于固定单元顺序)。
我正在调用 Xero 的 API,然后使用从 XML 步骤获取数据。如何提取折旧费用 - 218.8?我试过 /Rows/Row/Cells/Cell/Attributes/。和 Rows/Row/Cells/Cell/Value - 以及其他选项,但它们没有用。另一个问题是,如果我有多个帐户并且我需要准确地提取 'Depreciation Expense',我尝试使用 [] 来提取第 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>
对于像这样的复杂 XML 结构,通常最好使用嵌套 从 Pentaho 中的 XML 步骤获取数据。
在您的示例中(缺少根元素并关闭 /rows btw)它看起来像 XML 代表一个 Excel-like "rows with cells" 结构。这些单元格可能属于一列,具体取决于它们的顺序。对于这个答案,我假设这个顺序确实在 XML 中固定并且没有丢失的单元格。验证!
第一个 XML 步骤应该将每个 XML "row" 提取到 Pentaho 行中并返回 XML 节点,而不仅仅是一个值。为此,您可以使用 Loop XPath 设置 /YourRoot/Rows/Row 并获得带有 XPath "Cells" 和 [=23 的字段=]结果类型"Single node"。包含一个 rownum 字段可能会很好,select 如果需要,该选项。
然后第二个 XML 步骤可以使用第一个步骤的输出字段,从 Loop XPath /Cells/Cell 中提取并获取您需要使用的所有字段“获取字段”按钮。
获得字段后,使用 Select 值步骤删除原始 XML 字段,然后使用 Row Flattener(仅适用于固定单元顺序)。