getSibling(XML)
getSibling()所属R语言包:XML
Manipulate sibling XML nodes
操纵同级XML节点
译者:生物统计家园网 机器人LoveR
描述----------Description----------
These functions allow us to both access the sibling node to the left or right of a given node and so walk the chain of siblings, and also to insert a new sibling
这些功能让我们兄弟节点都访问一个给定节点的左或右,走连锁的兄弟姐妹,也插入一个新的兄弟姐妹
用法----------Usage----------
getSibling(node, after = TRUE, ...)
addSibling(node, ..., kids = list(...), after = NA)
参数----------Arguments----------
参数:node
the internal XML node (XMLInternalNode) whose siblings are of interest
内部XML节点(XMLInternalNode),有兴趣的兄弟姐妹
参数:...
the XML nodes to add as siblings or children to node.
XML节点添加到节点的父母,兄弟姐妹或子女。
参数:kids
a list containing the XML nodes to add as siblings. This is equivalent to ... but used when we already have the nodes in a list rather than as individual objects. This is used in programmatic calls to addSibling rather interactive use where we more commonly have the individual node objects.
一个列表,其中包含的XML节点添加的兄弟姐妹。这等同于...但使用时,我们已经有一个列表,而不是作为单独的对象中的节点。这是用在addSibling而是交互式的使用,我们更常见的各个节点对象的编程调用。
参数:after
a logical value indicating whether to retrieve or add the nodes to the right (TRUE) or to the left (FALSE) of this sibling.
一个逻辑值,该值指示是否要撷取或将节点添加到右边(TRUE)或左(FALSE)这兄弟。
值----------Value----------
getSibling returns an object of class XMLInternalNode (or some derived S3 class, e.g. XMLInternalTextNode)
getSibling返回一个对象,:类XMLInternalNode(或一些派生的S3类,如XMLInternalTextNode)
addSibling returns a list whose elements are the newly added XML (internal) nodes.
addSibling返回一个列表,它的元素是新加入的XML节点(内部)。
参见----------See Also----------
xmlChildren, addChildren removeNodes replaceNodes
xmlChildren,addChildrenremoveNodesreplaceNodes
实例----------Examples----------
# Reading Apple's iTunes files[阅读苹果公司的iTunes文件]
# []
# Here we read a "censored" "database" of songs from Apple's iTune application[在这里,我们读到了“封杀”,“资料库”的歌曲从苹果的iTune应用程序]
# which is stored in a property list. The format is quite generic and [它被存储在一个属性列表。该格式是通用的,]
# the fields for each song are given in the form[为每首歌曲的字段的形式给出]
# []
# <key>Artist</key><string>erson's name</string>[<KEY>艺术家</键> <String>的人的名字</字符串>]
# []
# So to find the names of the artists for all the songs, we want to [因此,要找到所有歌曲的艺术家的名字,我们要]
# find all the <key>Artist<key> nodes and then get their next sibling[找到所有的<key>的艺术家<KEY>节点,然后得到他们的下一个兄弟]
# which has the actual value.[它的实际价值。]
# []
# More information can be found in .[可以找到更多信息。]
# []
fileName = system.file("exampleData", "iTunes.plist", package = "XML")
doc = xmlParse(fileName)
nodes = getNodeSet(doc, "//key[text() = 'Artist']")
sapply(nodes, function(x) xmlValue(getSibling(x)))
f = system.file("exampleData", "simple.xml", package = "XML")
tt = as(xmlParse(f), "XMLHashTree")
tt
e = getSibling(xmlRoot(tt)[[1]])
# and back to the first one again by going backwards along the sibling list.[和背面的第一个再次倒退沿同级列表。]
getSibling(e, after = FALSE)
# This also works for multiple top-level "root" nodes[这也适用于多个顶层“根”节点]
f = system.file("exampleData", "job.xml", package = "XML")
tt = as(xmlParse(f), "XMLHashTree")
x = xmlRoot(tt, skip = FALSE)
getSibling(x)
getSibling(getSibling(x), after = FALSE)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|