是否可以使用POCO XPath获取元素文本

时间:2016-08-26 09:57:31

标签: c++ xml xpath poco poco-libraries

XML:

<root>
  <headers>
          <aaa>111</aaa>
          <bbb>222</bbb> 
  </headers>
</root>

我尝试过的一些xpath(找不到或者值为空):

/root/headers/bbb value[]       
/root/headers/aaa value[]       
/root/headers/bbb/text() could not be found.        
/root/headers/aaa/text() could not be found.        
//bbb value[]           
//bbb/text() could not be found.            
//bbb[1] could not be found.        
//aaa[0] value[]        
/root/headers/bbb[1] could not be found.        
/root/headers/aaa[0] value[]    

代码:

Poco::XML::XMLString xmlPath(xPath);
Poco::XML::Node* node = rootNode->getNodeByPath(xmlPath);
std::string value = node->nodeValue();

是否可以使用XPath获取111或222个值?

2 个答案:

答案 0 :(得分:0)

你走了:

//root//headers//text()

答案 1 :(得分:-1)

path <- 'yourpath'
d <- list.files(path)
d <- rep(d, each=4)
f <- c("0.csv", "1.csv", "2.csv", "3.csv")
l <- paste0(d,"/", f)
n <- paste0(path,l)
x <- list()

for (i in 1:length(d)) {
  x[[i]] <- read.csv(n[i], sep=",", header = TRUE)
}