У меня есть входной XML-файл. В файле есть данные о некоторых транзакциях. XML-файл выглядит так:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Message xmlns:bs="urn:iso:std:iso:20022:tech:xsd:camt.053.001.02"
xmlns="urn:bcsis"
xmlns:head="urn:iso:std:iso:20022:tech:xsd:head.001.001.01">
<bs:stmt>
<bs:Bal>
<bs:Tp>
<bs:CdOrPrtry>
<bs:Prtry>Outward</bs:Prtry>
</bs:CdOrPrtry>
</bs:Tp>
<bs:Amt Ccy="USD">300.00</bs:Amt>
<bs:CdtDbtInd>DBIT</bs:CdtDbtInd>
<bs:Dt>
<bs:Dt>2016-10-04</bs:Dt>
</bs:Dt>
</bs:Bal>
<bs:Ntry>
<bs:Amt Ccy="USD">300.00</bs:Amt>
</bs:Ntry>
</bs:stmt>
<bs:stmt>
<bs:Bal>
<bs:Tp>
<bs:CdOrPrtry>
<bs:Prtry>Inward</bs:Prtry>
</bs:CdOrPrtry>
</bs:Tp>
<bs:Amt Ccy="USD">250.00</bs:Amt>
<bs:CdtDbtInd>DBIT</bs:CdtDbtInd>
<bs:Dt>
<bs:Dt>2016-10-04</bs:Dt>
</bs:Dt>
</bs:Bal>
<bs:Ntry>
<bs:Amt Ccy="USD">250.00</bs:Amt>
</bs:Ntry>
</bs:stmt>
</Message>
Мне нужно извлечь суммы транзакций, для которых тип транзакции (bs: Prtry) - «Outward».
Вот что я сделал до сих пор:
library(xml2)
library(XML)
library(dplyr)
d <- read_xml("~/CEED/sample1.dat") # read the file
in_out <- xml_find_all(d, ".//bs:stmt/bs:Bal/bs:Tp/bs:CdOrPrtry/bs:Prtry") # Transaction Type
out_txns <- in_out[which(in_out %>% xml_text() == "Outward")] # Select only Outward
Вот что мне нужно сделать дальше:
- Перейдите к тегу bs: stmt внутри out_txns
- Найдите теги bs: Ntry, bs: Amt и извлеките значение
Я пробовал несколько вещей (xml_find_parents), но не смог найти правильный способ сделать это