找回密码
 注册
查看: 1329|回复: 0

R语言 XML包 addChildren()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-10-1 23:36:32 | 显示全部楼层 |阅读模式
addChildren(XML)
addChildren()所属R语言包:XML

                                        Add child nodes to an XML node
                                         添加一个XML节点的子节点

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

This collection of functions allow us to add, remove and replace children from an XML node and also to and and remove attributes on an XML node. These are generic functions that work on both internal C-level XMLInternalElementNode objects and regular R-level  XMLNode objects.
这个系列的功能,让我们添加,删除和替换孩子从一个XML节点,也和删除一个XML节点的属性。这些都是通用的功能,内部的C级XMLInternalElementNode对象和定期R-XMLNode对象。

addChildren is similar to addNode and the two may be consolidated into a single generic function and methods in the future.
addChildren是类似addNode和两个可能合并成一个通用的函数和方法在未来。


用法----------Usage----------


addChildren(node, ..., kids = list(...), at = NA, cdata = FALSE, append = TRUE)
removeChildren(node, ..., kids = list(...), free = FALSE)
removeNodes(node, free = rep(FALSE, length(node)))
replaceNodes(oldNode, newNode, ...)
addAttributes(node, ..., .attrs = NULL,
               suppressNamespaceWarning = getOption("suppressXMLNamespaceWarning", FALSE),
                append = TRUE)
removeAttributes(node, ..., .attrs = NULL, .namespace = FALSE,
                  .all = (length(list(...)) + length(.attrs)) == 0)




参数----------Arguments----------

参数:node
the XML node whose state is to be modified, i.e. to which the child nodes are to be added or whose attribute list is to be changed.
XML节点,其状态是要修改,即,该子节点是要添加或将被改变的属性列表。


参数:...
This is for use in interactive settings when specifying a collection of values individuall. In programming contexts when one obtains the collection as a vector or list from another call, use the kids or .attrs parameter.  
这是在互动设置指定的值的集合individuall。在编程环境中,当一个人获得作为向量或从另一个呼叫列表的收集,使用kids或.attrs参数。


参数:kids
when adding children to a node, this is a list of children nodes which should be of the same "type" (i.e. internal or R-level nodes) as the node argument. However, they can also be regular strings in which case they are converted to XML text nodes.  For removeChildren, this is again a list which identifies the child nodes to be removed using  the integer identifier of the child, or the name of the XML node (but this will only remove the first such node and not necessarily do what you expect when there are multiple nodes with the same name), or the XMLInternalNode object itself.  
孩子节点时,这是一个列表,这应该是相同的“类型”(即内部或R-级别的节点)作为node参数的子节点。然而,他们也可以是普通字符串,在这种情况下,它们被转换为XML文本节点。对于removeChildren,这又是一个列表,确定要删除的子节点使用的整数标识符的孩子,或XML节点的名称(不过这仅删除第一个这样的节点,而不是一定做什么您希望当有多个节点具有相同的名称),或XMLInternalNode“对象本身。


参数:at
if specified, an integer identifying the position in the original list of children at which the new children should be added. The children are added after that child. This can also be a vector of indices which is as long as the number of children being added and specifies the position for each child being added. If the vector is shorter than the number of children being added, it is padded with NAs and so the corresponding children are added at the end of the list.  This parameter is only implemented for internal nodes at present.  
如果指定了一个整数标识应加入新的儿童的儿童的原始列表中的位置。孩子们被添加后,孩子。这也可以是一个矢量的指数,这是只要作为所添加的儿童的数目,并指定为每个子被添加的位置。如果向量的数量比被添加的儿童短,它被填充和NAS(网络接入服务器),所以相应的儿童被添加在列表末尾。此参数只执行目前的内部节点。


参数:cdata
a logical value which controls whether children that are specified as strings/text are enclosed within a CDATA node when converted to actual nodes.  This value is passed on to the relevant function that creates the text nodes, e.g.  xmlTextNode and newXMLTextNode.  
一逻辑值,控制儿童是否被指定为字符串/文本时,被封闭在一个CDATA节点转换为实际的节点。该值被传递到相关的功能,创建文本节点,例如xmlTextNode和newXMLTextNode。


参数:.attrs
a character vector identifying the names of the attributes.  These strings can have name space prefixes, e.g. r:length and the namespaces will be resolved relative to the list supported by node to ensure those namespaces  are defined.  
字符向量识别的属性的名称。这些字符串可以有名称空间前缀,例如r:length和支持的node,以确保这些命名空间中定义的列表中的命名空间将得到解决。


参数:.namespace
This is currently ignored and may never be supported. The intent is to identify on which set of attributes the operation is to perform  - the name space declarations or the regular node attributes. This is a logical value indicating if  TRUE that  the attributes of interested are name space declarations, i.e. of the form xmlns:prefix or xmlns. If a value of  FALSE is supplied this indicates that we are identifying regular attributes. Note that we can still identify attributes with a name space prefix as, e.g., ns:attr without this value  
这是目前被忽略,并且可能永远不会被支持。这样做的目的是,以确定哪一组的属性的操作是执行 - 的名称空间声明或经常的节点属性。这是一个逻辑值,表示如果TRUE,有兴趣的属性的名称空间声明的形式xmlns:prefix或xmlns,即。如果值为FALSE提供这表明我们确定的常规属性。请注意,我们仍然可以识别属性的名称空间前缀,例如,ns:attr没有这个值的


参数:free
a logical value indicating whether to free the C-level memory associated with the  child      nodes that were removed. TRUE means to free that memory. This is only applicable for the internal nodes created with xmlTree and newXMLNode and related functions. It is necessary as automated garbage collection is tricky in this tree-based context spanning both R and C data structures and memory managers.   
一个逻辑值,该值指示是否释放被删除的子节点的C级相关联的内存。 TRUE是指以释放内存。这是只适用于创建xmlTree和newXMLNode和相关功能的内部节点。自动垃圾收集,这是必要的,因为在这个基于树的背景下,横跨R和C的数据结构和内存管理是非常复杂的。


参数:.all
a logical value indicating whether to remove all of the attributes within the XML node without having to specify them by name.
一个逻辑值,该值指示是否删除所有在XML节点的属性,而无需指定它们的名字。


参数:oldNode
the node which is to be replaced
要被替换的节点


参数:newNode
the node which is to take the place of oldNode in the list of children of the parent of oldNode
节点来代替的oldNode在列表中儿童的父oldNode的


参数:suppressNamespaceWarning
a logical value or a character string.  This is used to control the situation when an  XML node or attribute is created with a name space prefix that currently has no definition for that node.  This is not necessarily an error but can lead to one. This argument controls whether a warning is issued or if a separate function is called. A value of FALSE means not to suppress the warning and  so it is issued. A value of TRUE causes the potential problem to be ignored assuming that the namespace will be added to this node or one of its ancestors at a later point. And if this value is a character string, we search for a function of that name and invoke it.   
一个逻辑值,或者是一个字符串。这是用来控制创建一个XML节点或属性的情况下,当与当前没有定义该节点的名称空间的前缀。这不一定是一个错误,但可能会导致1。此参数控制是否发出警告,如果一个单独的函数被调用。 FALSE值是指不抑制警告,所以它发出的。值TRUE导致潜在的假设命名空间将被添加到该节点或它的一个祖先在以后的某个被忽略的问题。如果这个值是一个字符串,搜索该名称的函数和调用它。


参数:append
a logical value that indicates whether (TRUE) the specified attributes or children should be added to the existing  attributes on the XML node (if any exist), or, if FALSE these should replace any existing attributes.
一逻辑值,指明是否(TRUE)指定的属性或子应该被添加到现有的属性的XML节点(如果存在的话),或者,如果FALSE应替换任何现有的属性。


值----------Value----------

Each of these functions returns the modified node. For an internal node, this is the same R object   and only the C-level data structures have changed. For an R XMLNode object, this is is an entirely separate object from the original node. It must be inserted back into its parent "node" or context if the changes are to be seen in that wider context.
这些函数中的每一个都返回修改后的节点。对于一个内部节点,这是相同的R对象和只有C-级的数据结构已经改变。对于RXMLNode对象,这是一个完全独立的对象从原来的节点。必须将它插回到它的父“节点”或上下文,如果要在更广泛的范围内的变化。


(作者)----------Author(s)----------


Duncan Temple Lang



参考文献----------References----------



参见----------See Also----------

xmlTree newXMLNode
xmlTreenewXMLNode


实例----------Examples----------



b = newXMLNode("bob", namespace = c(r = "http://www.r-project.org", omg = "http://www.omegahat.org"))

cat(saveXML(b), "\n")

addAttributes(b, a = 1, b = "xyz", "r:version" = "2.4.1", "omg:len" = 3)
cat(saveXML(b), "\n")

removeAttributes(b, "a", "r:version")
cat(saveXML(b), "\n")


removeAttributes(b, .attrs = names(xmlAttrs(b)))


addChildren(b, newXMLNode("el", "Red", "Blue", "Green",
                           attrs = c(lang ="en")))

k = lapply(letters, newXMLNode)
addChildren(b, kids = k)

cat(saveXML(b), "\n")

removeChildren(b, "a", "b", "c", "z")

  # can mix numbers and names[可以混合号码和姓名]
removeChildren(b, 2, "e")  # d and e[d和e]

cat(saveXML(b), "\n")


i = xmlChildren(b)[[5]]
xmlName(i)

# have the identifiers[有标识符]
removeChildren(b, kids = c("m", "n", "q"))



x <- xmlNode("a",
               xmlNode("b", "1"),
               xmlNode("c", "1"),
               "some basic text")

v = removeChildren(x, "b")

  # remove c and b[删除c和b]
v = removeChildren(x, "c", "b")

  # remove the text and "c" leaving just b[删除文本和“c”,只留下b]
v = removeChildren(x, 3, "c")

## Not run: [#不运行:]
    # this won't work as the 10 gets coerced to a [这将无法正常工作的10个被强制转换为]
    # character vector element to be combined with 'w'[字符向量元素结合W]
    # and there is no node name 10.[和有没有节点名10。]
removeChildren(b, kids = c(10, "w"))

## End(Not run)[#(不执行)]


# for R-level nodes (not internal)[R-级别的节点(而不是内部)]

z = xmlNode("arg", attrs = c(default="TRUE"),
              xmlNode("name", "foo"), xmlNode("defaultValue","1:10"))

o = addChildren(z,
                "some text",
                xmlNode("a", "a link", attrs = c(href = "http://www.omegahat.org/RSXML")))
o


  # removing nodes[删除节点]

doc = xmlParse("<top><a/><b/><c><d/><e>bob</e></c></top>")
top = xmlRoot(doc)
top

removeNodes(list(top[[1]], top[[3]]))

    # a and c have disappeared.[A和C都消失了。]
top


转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2024-11-24 15:48 , Processed in 0.020076 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表