getNodeSet(XML)
getNodeSet()所属R语言包:XML
Find matching nodes in an internal XML tree/DOM
找到匹配的内部XML树/ DOM节点
译者:生物统计家园网 机器人LoveR
描述----------Description----------
These functions provide a way to find XML nodes that match a particular criterion. It uses the XPath syntax and allows very powerful expressions to identify nodes of interest within a document both clearly and efficiently. The XPath language requires some knowledge, but tutorials are available on the Web and in books. XPath queries can result in different types of values such as numbers, strings, and node sets. It allows simple identification of nodes by name, by path (i.e. hierarchies or sequences of node-child-child...), with a particular attribute or matching a particular attribute with a given value. It also supports functionality for navigating nodes in the tree within a query (e.g. ancestor(), child(), self()), and also for manipulating the content of one or more nodes (e.g. text). And it allows for criteria identifying nodes by position, etc. using some counting operations. Combining XPath with R allows for quite flexible node identification and manipulation. XPath offers an alternative way to find nodes of interest than recursively or iteratively navigating the entire tree in R and performing the navigation explicitly.
这些功能提供了一种方法来找出符合特定标准的XML节点。它使用XPath的语法和非常强大的表达式,可以在一个文件中都明确和有效地识别节点的兴趣。 XPath语言需要一些知识,但教程可以在网络上和书籍。 XPath查询可以在不同类型的值,如数字,字符串和节点集。它允许简单的识别节点的名称,路径(即层次结构或序列节点的孩子,孩子...),具有特定属性或一个特定的属性与给定值相匹配。它还支持的功能用于导航树中的节点内的查询(例如ancestor(),child(),self()),也可用于操作的内容的一个或多个节点(例如<X >)。它允许标准确定节点的位置,等使用一些计数操作。结合与R的XPath可以相当灵活的节点识别和操作。 XPath还提供节点的利率比递归或迭代浏览整个目录树在R和明确的执行导航的另一种方式。
One can search an entire document or start the search from a particular node. Such node-based searches can even search up the tree as well as within the sub-tree that the node parents. Node specific XPath expressions are typically started with a "." to indicate the search is relative to that node.
人们可以搜索整个文件或从一个特定的节点开始搜索。这种基于节点的搜索,甚至可以搜索树的子树内的节点父母。节点特定的XPath表达式通常开始用“。”来表示搜索到该节点是相对的。
The set of matching nodes corresponding to an XPath expression are returned in R as a list. One can then iterate over these elements to process the nodes in whatever way one wants. Unfortunately, this involves two loops - one in the XPath query over the entire tree, and another in R. Typically, this is fine as the number of matching nodes is reasonably small. However, if repeating this on numerous files, speed may become an issue. We can avoid the second loop (i.e. the one in R) by applying a function to each node before it is returned to R as part of the node set. The result of the function call is then returned, rather than the node itself.
匹配节点的一组对应的XPath表达式返回在R为一个列表。然后遍历这些元素节点中的任何人想要的方式来处理。不幸的是,这涉及到两个循环 - 通常在XPath查询整个树,并在R.,这是很好的匹配节点的数量是相当小的。但是,如果重复大量的文件,速度可能会成为一个问题。我们能够避免第二环路(即在R 1)之前,每个节点的节点集的一部分,它被返回到R作为通过应用一个函数。然后,返回的函数调用的结果,而不是节点本身。
One can provide an R expression rather than an R function for fun. This is expected to be a call and the first argument of the call will be replaced with the node.
我们可以提供R的表达,而不是为funR的功能。这是预期的是一个呼叫,该呼叫的第一个参数与该节点将被替换。
Dealing with expressions that relate to the default namespaces in the XML document can be confusing.
处理涉及到的默认命名空间的XML文档中的表达式可以是混乱。
xpathSApply is a version of xpathApply which attempts to simplify the result if it can be converted to a vector or matrix rather than left as a list. In this way, it has the same relationship to xpathApply as sapply has to lapply.
xpathSApply是xpathApply,它试图以简化的结果,如果它可以被转换为作为一个列表的向量或矩阵,而不是离开的一个版本。以这种方式,它具有相同的关系xpathApplysapply有lapply。
matchNamespaces is a separate function that is used to facilitate specifying the mappings from namespace prefix used in the XPath expression and their definitions, i.e. URIs, and connecting these with the namespace definitions in the target XML document in which the XPath expression will be evaluated.
matchNamespaces是一个单独的函数是用来方便指定命名空间前缀使用XPath表达式,它们的定义,即URI的映射关系,以及连接这些目标XML文档中的命名空间中定义的XPath表达式将进行评估。
matchNamespaces uses rules that are very slightly awkard or specifically involve a special case. This is because this mapping of namespaces from XPath to XML targets is difficult, involving prefixes in the XPath expression, definitions in the XPath evaluation context and matches of URIs with those in the XML document. The function aims to avoid having to specify all the prefix=uri pairs by using "sensible" defaults and also matching the prefixes in the XPath expression to the corresponding definitions in the XML document.
matchNamespaces使用规则是非常轻微的awkard或特别涉及一种特殊情况。这是因为这种映射的XML目标命名空间的XPath是困难的,涉及前缀的XPath表达式,在XPath求值上下文中的定义在XML文档中的URI和比赛。该功能的目的是为了避免不必指定所有的前缀URI对使用“明智”的默认值和匹配前缀的XPath表达式在XML文档中的相应定义。
The rules are as follows. namespaces is a character vector. Any element that has a non-trivial name (i.e. other than "") is left as is and the name and value define the prefix = uri mapping. Any elements that have a trivial name (i.e. no name at all or "") are resolved by first matching the prefix to those of the defined namespaces anywhere within the target document, i.e. in any node and not just the root one. If there is no match for the first element of the namespaces vector, this is treated specially and is mapped to the default namespace of the target document. If there is no default namespace defined, an error occurs.
的规则如下。 namespaces是一个字符向量。是的名称和值= URI的映射中定义的前缀,剩下的任何元素,有一个不平凡的名字(即除“)。有一个简单的名称(即没有在所有的名称或“”)的所有元素都解决了第一个匹配的前缀定义的命名空间内的任何地方的目标文件,即在任一节点,而不是只是根。如果没有匹配的第一个元素的namespaces矢量,这是经过特殊处理,并映射到目标文档的默认命名空间。如果没有默认定义的命名空间,就会发生错误。
It is best to give explicit the argument in the form c(prefix = uri, prefix = uri). However, one can use the same namespace prefixes as in the document if one wants. And one can use an arbitrary namespace prefix for the default namespace URI of the target document provided it is the first element of namespaces.
这是最好的形式c(prefix = uri, prefix = uri)给予明确的说法。然而,人们可以在文档中使用相同的命名空间的前缀,如果一个人想。可以使用一个任意的命名空间前缀的默认命名空间URI的目标文件,它是第一个元素namespaces。
See the 'Details' section below for some more information.
用法----------Usage----------
getNodeSet(doc, path, namespaces = xmlNamespaceDefinitions(doc, simplify = TRUE),
fun = NULL, sessionEncoding = CE_NATIVE, addFinalizer = NA, ...)
xpathApply(doc, path, fun, ... ,
namespaces = xmlNamespaceDefinitions(doc, simplify = TRUE),
resolveNamespaces = TRUE, addFinalizer = NA)
xpathSApply(doc, path, fun = NULL, ... ,
namespaces = xmlNamespaceDefinitions(doc, simplify = TRUE),
resolveNamespaces = TRUE, simplify = TRUE, addFinalizer = NA)
matchNamespaces(doc, namespaces,
nsDefs = xmlNamespaceDefinitions(doc, recursive = TRUE),
defaultNs = getDefaultNamespace(doc))
参数----------Arguments----------
参数:doc
an object of class XMLInternalDocument
一个对象的类XMLInternalDocument
参数:path
a string (character vector of length 1) giving the XPath expression to evaluate.
一个字符串(字符向量长度为1)的XPath表达式进行评估。
参数:namespaces
a named character vector giving the namespace prefix and URI pairs that are to be used in the XPath expression and matching of nodes. The prefix is just a simple string that acts as a short-hand or alias for the URI that is the unique identifier for the namespace. The URI is the element in this vector and the prefix is the corresponding element name. One only needs to specify the namespaces in the XPath expression and for the nodes of interest rather than requiring all the namespaces for the entire document. Also note that the prefix used in this vector is local only to the path. It does not have to be the same as the prefix used in the document to identify the namespace. However, the URI in this argument must be identical to the target namespace URI in the document. It is the namespace URIs that are matched (exactly) to find correspondence. The prefixes are used only to refer to that URI.
要使用的XPath表达式匹配的节点的命名空间前缀和URI对指定的字符向量。前缀是只是一个简单的字符串,作为一个短手或别名的唯一标识符的命名空间的URI。 URI是此向量中的元素,前缀是对应的元素的名称。我们只需要指定命名空间的XPath表达式,感兴趣的节点而不需要对整个文档的所有命名空间。另外请注意,在这个向量中使用的前缀是当地唯一的路径。它不必是相同的文档中使用的,以确定的命名空间的前缀。然而,在这个参数中的URI必须是相同的目标命名空间URI在文档中。它是相匹配(精确)找到对应的命名空间URI。前缀仅用于参考该URI。
参数:fun
a function object, or an expression or call, which is used when the result is a node set and evaluated for each node element in the node set. If this is a call, the first argument is replaced with the current node.
一个函数对象,或表达或呼叫,这是用来当结果是一个节点,每个节点的元素集合中的节点设置和评价。如果这是一个呼叫,第一个参数被替换为当前节点。
参数:...
any additional arguments to be passed to fun for each node in the node set.
任何额外的参数被传递到fun中的每个节点的节点集。
参数:resolveNamespaces
a logical value indicating whether to process the collection of namespaces and resolve those that have no name by looking in the default namespace and the namespace definitions within the target document to match by prefix.
一个逻辑值,该值指示是否要处理的命名空间集合和解决那些没有名字,在默认的命名空间和命名空间定义在目标文件的前缀匹配。
参数:nsDefs
a list giving the namespace definitions in which to match any prefixes. This is typically computed directly from the target document and the default value is most appropriate.
一个列表,给出匹配任何前缀的命名空间定义。这通常是直接计算从目标文件,默认值是最合适的。
参数:defaultNs
the default namespace prefix-URI mapping given as a named character vector. This is not a namespace definition object. This is used when matching a simple prefix that has no corresponding entry in nsDefs and is the first element in the namespaces vector.
默认的命名空间前缀-URI的映射指定的字符向量。这是不是一个命名空间定义的对象。这是用来匹配时,有没有相应的条目在nsDefs的namespaces矢量的第一个元素是一个简单的前缀。
参数:simplify
a logical value indicating whether the function should attempt to perform the simplification of the result into a vector rather than leaving it as a list. This is the same as sapply does in comparison to lapply.
一个逻辑值,该值指示功能是否尝试执行的结果简化成一个向量,而不是把它当作一个列表。这是相同的sapply不相比lapply。
参数:sessionEncoding
experimental functionality and parameter related to encoding.
实验的功能和相关的编码参数。
参数:addFinalizer
a logical value or identifier for a C routine that controls whether we register finalizers on the intenal node.
C程序,控制我们是否终结的内置式节点上注册一个逻辑值或标识符。
Details
详细信息----------Details----------
When a namespace is defined on a node in the XML document, an XPath expressions must use a namespace, even if it is the default namespace for the XML document/node. For example, suppose we have an XML document <help xmlns="http://www.r-project.org/Rd"><topic>...</topic></help> To find all the topic nodes, we might want to use the XPath expression "/help/topic". However, we must use an explicit namespace prefix that is associated with the URI http://www.r-project.org/Rd corresponding to the one in the XML document. So we would use getNodeSet(doc, "/r:help/r:topic", c(r = "http://www.r-project.org/Rd")).
当一个命名空间被定义在XML文档中的节点上,一个XPath表达式必须使用一个命名空间,即使它是默认的命名空间的XML文档/节点。例如,假设我们有一个XML文件<help xmlns="http://www.r-project.org/Rd"><topic>...</topic></help>要找到所有的主题节点,我们可能要使用的XPath表达式"/help/topic"。但是,我们必须使用一个显式的命名空间前缀是与URIhttp://www.r-project.org/Rd相应的XML文档中的一个。因此,我们将使用getNodeSet(doc, "/r:help/r:topic", c(r = "http://www.r-project.org/Rd"))。
As described above, the functions attempt to allow the namespaces to be specified easily by the R user and matched to the namespace definitions in the target document.
如上所述,功能尝试,以允许容易地由R用户指定的命名空间和匹配,以在目标文件中的命名空间定义。
This calls the libxml routine xmlXPathEval.
这就要求libxml的日常xmlXPathEval。
值----------Value----------
The results can currently be different based on the returned value from the XPath expression evaluation:
结果目前可以依据不同的XPath表达式求值的返回值:
参数:list
a node set
一个节点集
参数:numeric
a number
数字
参数:logical
a boolean
一个布尔值,
参数:character
a string, i.e. a single character element.
的字符串,即一个单一的字符元件。
If fun is supplied and the result of the XPath query is a node set, the result in R is a list.
如果fun提供的XPath查询的结果是一个节点集,结果在R是一个列表。
注意----------Note----------
In order to match nodes in the default name space for documents with a non-trivial default namespace, e.g. given as xmlns="http://www.omegahat.org", you will need to use a prefix for the default namespace in this call. When specifying the namespaces, give a name - any name - to the default namespace URI and then use this as the prefix in the XPath expression, e.g. getNodeSet(d, "//d:myNode", c(d = "http://www.omegahat.org")) to match myNode in the default name space http://www.omegahat.org.
为了配合一个不平凡的默认命名空间的默认名称空间的文档中的节点,例如xmlns="http://www.omegahat.org",您将需要使用一个前缀为默认命名空间,在这个调用。在指定的命名空间,给了一个名字 - 任何名称 - 默认的命名空间URI,然后使用的XPath表达式中的前缀,例如: getNodeSet(d, "//d:myNode", c(d = "http://www.omegahat.org")),以配合MYNODE的默认名称空间http://www.omegahat.org。
This default namespace of the document is now computed for us and is the default value for the namespaces argument. It can be referenced using the prefix 'd', standing for default but sufficiently short to be easily used within the XPath expression.
此默认命名空间的文件,现在计算的是为我们的命名空间参数的默认值。可以使用前缀“D”,但默认情况下,在XPath表达式可以很容易地使用足够短的引用。
More of the XPath functionality provided by libxml can and may be made available to the R package. Facilities such as compiled XPath expressions, functions, ordered node information are examples.
更多的XPath功能所提供的与libxml可以,并且可以由提供给R包。如编译的XPath表达式,函数,设施下令节点信息的例子。
Please send requests to the package maintainer.
请发送请求到软件包的维护者。
(作者)----------Author(s)----------
Duncan Temple Lang <duncan@wald.ucdavis.edu>
参考文献----------References----------
http://www.w3.org/xml http://www.w3.org/TR/xpath http://www.omegahat.org/RSXML
参见----------See Also----------
xmlTreeParse with useInternalNodes as TRUE.
实例----------Examples----------
doc = xmlParse(system.file("exampleData", "tagnames.xml", package = "XML"))
els = getNodeSet(doc, "/doc//a[@status]")
sapply(els, function(el) xmlGetAttr(el, "status"))
# use of namespaces on an attribute.[在一个属性上使用的命名空间。]
getNodeSet(doc, "/doc//b[@x:status]", c(x = "http://www.omegahat.org"))
getNodeSet(doc, "/doc//b[@x:status='foo']", c(x = "http://www.omegahat.org"))
# Because we know the namespace definitions are on /doc/a[因为我们知道,命名空间定义/ DOC /]
# we can compute them directly and use them.[我们可以直接计算和使用它们。]
nsDefs = xmlNamespaceDefinitions(getNodeSet(doc, "/doc/a")[[1]])
ns = structure(sapply(nsDefs, function(x) x$uri), names = names(nsDefs))
getNodeSet(doc, "/doc//b[@omegahat:status='foo']", ns)[[1]]
# free(doc) [免费(DOC)]
#####[####]
f = system.file("exampleData", "eurofxref-hist.xml.gz", package = "XML")
e = xmlParse(f)
ans = getNodeSet(e, "//o:Cube[@currency='USD']", "o")
sapply(ans, xmlGetAttr, "rate")
# or equivalently[或等价]
ans = xpathApply(e, "//o:Cube[@currency='USD']", xmlGetAttr, "rate", namespaces = "o")
# free(e)[免费(E)]
# Using a namespace[使用命名空间]
f = system.file("exampleData", "SOAPNamespaces.xml", package = "XML")
z = xmlParse(f)
getNodeSet(z, "/a:Envelope/a:Body", c("a" = "http://schemas.xmlsoap.org/soap/envelope/"))
getNodeSet(z, "//a:Body", c("a" = "http://schemas.xmlsoap.org/soap/envelope/"))
# free(z)[免费(Z)]
# Get two items back with namespaces[两个项目的命名空间]
f = system.file("exampleData", "gnumeric.xml", package = "XML")
z = xmlParse(f)
getNodeSet(z, "//gmr:Item/gmr:name", c(gmr="http://www.gnome.org/gnumeric/v2"))
#free(z)[免费(Z)]
#####[####]
# European Central Bank (ECB) exchange rate data[欧洲央行(ECB)汇率数据]
# Data is available from "http://www.ecb.int/stats/eurofxref/eurofxref-hist.xml"[数据可“http://www.ecb.int/stats/eurofxref/eurofxref-hist.xml”]
# or locally.[或在本地。]
uri = system.file("exampleData", "eurofxref-hist.xml.gz", package = "XML")
doc = xmlParse(uri)
# The default namespace for all elements is given by[默认的命名空间的所有元素]
namespaces <- c(ns="http://www.ecb.int/vocabulary/2002-08-01/eurofxref")
# Get the data for Slovenian currency for all time periods.[所有时间段的数据,斯洛文尼亚货币。]
# Find all the nodes of the form <Cube currency="SIT"...>[所有的节点形式<Cube currency="SIT"...>的]
slovenia = getNodeSet(doc, "//ns:Cube[@currency='SIT']", namespaces )
# Now we have a list of such nodes, loop over them [现在我们有一个这样的节点列表,循环]
# and get the rate attribute[和速率属性]
rates = as.numeric( sapply(slovenia, xmlGetAttr, "rate") )
# Now put the date on each element[现在把每个元素上的日期]
# find nodes of the form <Cube time=".." ... >[查找节点的形式<立方=“..” ... >]
# and extract the time attribute[和提取时间属性]
names(rates) = sapply(getNodeSet(doc, "//ns:Cube[@time]", namespaces ),
xmlGetAttr, "time")
# Or we could turn these into dates with strptime()[或者,我们可以把这些日期,那么strptime()]
strptime(names(rates), "%Y-%m-%d")
# Using xpathApply, we can do[使用xpathApply,我们可以做的]
rates = xpathApply(doc, "//ns:Cube[@currency='SIT']", xmlGetAttr, "rate", namespaces = namespaces )
rates = as.numeric(unlist(rates))
# Using an expression rather than a function and ...[使用表达式,而不是一个函数,...]
rates = xpathApply(doc, "//ns:Cube[@currency='SIT']", quote(xmlGetAttr(x, "rate")), namespaces = namespaces )
#free(doc)[免费(DOC)]
#[]
uri = system.file("exampleData", "namespaces.xml", package = "XML")
d = xmlParse(uri)
getNodeSet(d, "//c:c", c(c="http://www.c.org"))
getNodeSet(d, "/o:a//c:c", c("o" = "http://www.omegahat.org", "c" = "http://www.c.org"))
# since http://www.omegahat.org is the default namespace, we can[因为http://www.omegahat.org是默认的命名空间,我们可以]
# just the prefix "o" to map to that.[只是“O”的前缀映射到该。]
getNodeSet(d, "/o:a//c:c", c("o", "c" = "http://www.c.org"))
# the following, perhaps unexpectedly but correctly, returns an empty[下面,也许是意外,但正确,则返回空]
# with no matches[没有比赛]
getNodeSet(d, "//defaultNs", "http://www.omegahat.org")
# But if we create our own prefix for the evaluation of the XPath[但是,如果我们创建了我们自己的前缀的XPath评估]
# expression and use this in the expression, things work as one[表达中的表达,作为一个]
# might hope.[可能希望。]
getNodeSet(d, "//dummy:defaultNs", c(dummy = "http://www.omegahat.org"))
# And since the default value for the namespaces argument is the[而且,由于命名空间参数的默认值是]
# default namespace of the document, we can refer to it with our own[默认的命名空间的文件,大家可以参考它与我们自己的]
# prefix given as [前缀表示为]
getNodeSet(d, "//d:defaultNs", "d")
# And the syntactic sugar is [,句法糖]
d["//d:defaultNs", namespace = "d"]
# this illustrates how we can use the prefixes in the XML document[这说明我们如何能够在XML文档中使用前缀]
# in our query and let getNodeSet() and friends map them to the[在我们的的查询,让getNodeSet的()和朋友将它们映射到]
# actual namespace definitions.[实际命名空间定义。]
# "o" is used to represent the default namespace for the document[“O”是用来表示的默认命名空间的文件]
# i.e. http://www.omegahat.org, and "r" is mapped to the same[即http://www.omegahat.org,和“r”被映射到相同的]
# definition that has the prefix "r" in the XML document.[定义具有在XML文档中的“r”的前缀。]
tmp = getNodeSet(d, "/o:a/r:b/o:defaultNs", c("o", "r"))
xmlName(tmp[[1]])
#free(d)[免费(D)]
# Work with the nodes and their content (not just attributes) from the node set.[工作的节点和节点集的内容(不只是属性)。]
# From bondsTables.R in examples/[从bondsTables.R在examples /]
doc = htmlTreeParse("http://finance.yahoo.com/bonds/composite_bond_rates", useInternalNodes = TRUE)
if(is.null(xmlRoot(doc)))
doc = htmlTreeParse("http://finance.yahoo.com/bonds", useInternalNodes = TRUE)
# Use XPath expression to find the nodes [使用XPath表达式来查找节点]
# <div><table class="yfirttbl">..[<DIV>表class="yfirttbl"> ..]
# as these are the ones we want.[这些都是我们想要的。]
if(!is.null(xmlRoot(doc))) {
o = getNodeSet(doc, "//div/table[@class='yfirttbl']")
# Write a function that will extract the information out of a given table node.[写一个函数,将一个给定的表节点中提取信息。]
readHTMLTable =
function(tb)
{
# get the header information.[得到的标头信息。]
colNames = sapply(tb[["thead"]][["tr"]]["th"], xmlValue)
vals = sapply(tb[["tbody"]]["tr"], function(x) sapply(x["td"], xmlValue))
matrix(as.numeric(vals[-1,]),
nrow = ncol(vals),
dimnames = list(vals[1,], colNames[-1]),
byrow = TRUE
)
}
# Now process each of the table nodes in the o list.[现在,处理每个邻列表中的表节点。]
tables = lapply(o, readHTMLTable)
names(tables) = lapply(o, function(x) xmlValue(x[["caption"]]))
}
# this illustrates an approach to doing queries on a sub tree[这说明了一个子树的方法来进行查询]
# within the document.[在文档中。]
# Note that there is a memory leak incurred here as we create a new[需要注意的是内存泄漏产生的,在这里我们创建了一个新的]
# XMLInternalDocument in the getNodeSet().[XMLInternalDocument的getNodeSet()中。]
f = system.file("exampleData", "book.xml", package = "XML")
doc = xmlParse(f)
ch = getNodeSet(doc, "//chapter")
xpathApply(ch[[2]], "//section/title", xmlValue)
# To fix the memory leak, we explicitly create a new document for[为了解决内存泄露,我们显式地创建一个新的文件]
# the subtree, perform the query and then free it _when_ we are done[子树,执行查询,然后释放它_when_我们已经完成了]
# with the resulting nodes.[与所得到的节点。]
subDoc = xmlDoc(ch[[2]])
xpathApply(subDoc, "//section/title", xmlValue)
free(subDoc)
txt = '<top xmlns="http://www.r-project.org" xmlns:r="http://www.r-project.org"><r:a><b/></r:a></top>'
doc = xmlInternalTreeParse(txt, asText = TRUE)
## Not run: [#不运行:]
# Will fail because it doesn't know what the namespace x is[将失败,因为它不知道的命名空间,x是什么]
# and we have to have one eventhough it has no prefix in the document.[,我们必须有一个追诉的,它没有前缀的文件。]
xpathApply(doc, "//x:b")
## End(Not run) [#(不执行)]
# So this is how we do it - just say x is to be mapped to the[因此,这是我们如何做到这一点 - 只是说,x是被映射到]
# default unprefixed namespace which we shall call x![默认情况下不带前缀的命名空间,我们将调用X!]
xpathApply(doc, "//x:b", namespaces = "x")
# Here r is mapped to the the corresponding definition in the document.[在这里,r是映射到文档中的相应定义。]
xpathApply(doc, "//r:a", namespaces = "r")
# Here, xpathApply figures this out for us, but will raise a warning.[在这里,xpathApply数字这一点对我们来说,反而会发出警告。]
xpathApply(doc, "//r:a")
# And here we use our own binding.[在这里,我们用我们自己的绑定。]
xpathApply(doc, "//x:a", namespaces = c(x = "http://www.r-project.org"))
# Get all the nodes in the entire tree.[在整个树中的所有节点。]
table(unlist(sapply(doc["//*|//text()|//comment()|//processing-instruction()"],
class)))
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|