Xml 确定一个div有多少子级

Xml 确定一个div有多少子级,xml,r,Xml,R,如何使用xml确定div class=“pagination”有多少个元素 <div class="pagination"> <span class="current"> 1 </span> <a class="" href="#"> 2 </a> <a class="" href="#"> 3 </a> <a class="" hre

如何使用xml确定
div class=“pagination”
有多少个元素

<div class="pagination">
   <span class="current">
     1
   </span>
   <a class="" href="#">
     2
   </a>
   <a class="" href="#">
     3
   </a>
   <a class="" href="#">
     4
   </a>
</div>

1
输出应该是:4

更新1:

我试过这个:

library(XML)
urrrl <- "http://www.tagesanzeiger.ch/service/suche/suche.html?order=relevanz&q=Ecopop&submitSearch=Suchen&date=alle#"
download.file(url = urrrl, destfile = "overview.xml")
parsed <- htmlParse("overview.xml") 

nodes <-  getNodeSet(parsed, "//div[@class='pagination']")  
nodes
   list()
   attr(,"class")
   [1] "XMLNodeSet"

aid <- lapply(nodes, function(x) xmlSApply(x, xmlValue))
aid
   list()
库(XML)

urrrl您可以使用XML 1.0的
count()
函数。 以下是一个例子:

doc <- htmlTreeParse("http://www.cgalaw.com/contact", useInternal = TRUE)

(string <- xpathSApply(doc, "count(//h3)", xmlValue, trim = TRUE)) 

[1] 5

此XPath:
//div[@class='pagination']/*
返回
..@har07的所有子元素。这对我不起作用。我可能会犯错误。你能写完整的代码吗?谢谢你。不幸的是,它返回0而不是4。我已经用另一种方式解决了这个问题,但我仍然很想知道还有什么方法可以解决这个问题。很高兴你解决了你的问题。我修改后的表达有效吗?不幸的是没有。。。我仍然得到0。
xpathSApply(doc, "count(div[@class='pagination'])", xmlValue, trim = TRUE)