如何从db2中的xml字符串读取值

时间:2019-12-09 01:14:20

标签: sql xml db2

我在“ Inbound”表的“ RawData”列中有一个xml字符串,我必须从一个名为“ status”的元素中读取“ Success”值。

xmlstring:

<InboundMessage><Transaction><Status>Success</Status></Transaction></InboundMessage>

1 个答案:

答案 0 :(得分:0)

  1. 正则表达式:paste。 Java代码:
maxfn <- function(a, b, c){

  do.call(paste, subset( data.frame(col1 = strrep(letters[1:3], 3), 
           col2 = c(a, b,  c)), col2 == max(col2)))
  }

maxfn(3, 2, 1)
#[1] "aaa 3"

maxfn(3, 2, 10)
#[1] "ccc 10"
  1. XML解析lib,就像dom4j。 Java代码:
<Status>(\w*)<\/Status>
  1. 如果需要,请执行Sql。 mysql:
String in = "<InboundMessage><Transaction><Status>Success</Status></Transaction></InboundMessage>";
Pattern compile = Pattern.compile("<Status>(\\w*)<\\/Status>");
Matcher matcher = compile.matcher(in);
if (matcher.find()) {
    System.out.println(matcher.group(1));
}