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

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

[复制链接]
发表于 2012-10-2 07:10:16 | 显示全部楼层 |阅读模式
xmlTree(XML)
xmlTree()所属R语言包:XML

                                        An internal, updatable DOM object for building XML trees
                                         内部的,可更新的DOM对象创建XML树

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

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

This is a mutable object (implemented via a closure) for representing an XML tree, in the same spirit as xmlOutputBuffer and xmlOutputDOM but that uses the internal structures of libxml. This can be used to create a DOM that can be  constructed in R and exported to another system such as XSLT (http://www.omegahat.org/Sxslt)
这是一个可变对象(实现通过闭包)为代表的XML树,在相同的精神xmlOutputBuffer和xmlOutputDOM,但使用的libxml的内部结构。这可以被用来创建一个DOM可以建造在R和出口到另一个系统如XSLT(http://www.omegahat.org/Sxslt)


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


xmlTree(tag, attrs = NULL, dtd=NULL, namespaces=list(),
          doc = newXMLDoc(dtd, namespaces))



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

参数:tag
the node or element name to use to create the new top-level node in the tree or alternatively, an XMLInternalNode that was already created. This is optional. If it is not specified, no top-most node is created but can be added using addNode. If a top-level tag is added in the call to xmlTree,  that becomes the currently active or open node (e.g. same as addNode( ..., close = FALSE)) and nodes subsequently added to this  
使用它来创建新的顶级树中的节点或者节点或元素的名称,XMLInternalNode,已经创建。这是可选的。如果没有指定,没有最上面的节点被创建,但可以添加使用addNode。如果顶层标签,这将成为当前活动或开放的节点(例如一样xmlTree)和节点中添加调用addNode( ..., close = FALSE)后来加入此


参数:attrs
attributes for the top-level node, in the form of a named character vector.
顶级节点的属性,在指定的字符向量的形式。


参数:dtd
the name of the external DTD for this document. If specified, this adds the DOCTYPE node to the resulting document. This can be a node created earlier with a call to  newXMLDTDNode, or alternatively it can be a character vector with 1, 2 or 3 elements giving the name of the top-level node, and the public identifier and the system identifier for the DTD in that order.  
外部DTD此文档的名称。如果指定,这增加了DOCTYPE节点所产生的文件。这可以是一个节点先前创建呼叫到newXMLDTDNode,或者它可以是一个字符矢量用1,2或3个元素,给人的顶层节点的名称,和公共标识符和系统标识符的DTD的顺序。


参数:namespaces
a named character vector with each element giving the name space identifier and the corresponding URI, \ e.g c(shelp = "http://www.omegahat.org/XML/SHelp") If tag is specified as a character vector, these name spaces are defined within that new node.  
指定的字符向量的每个元素提供的名字空间的标识符和相应的URI,\例如c(shelp = "http://www.omegahat.org/XML/SHelp")如果tag被指定作为一个字符向量,这些名称空间内定义的该新节点。


参数:doc
an internal XML document object, typically created with newXMLDoc. This is used as the host document for all the new nodes that will be created  as part of this document. If one wants to create nodes without an internal document ancestor, one can alternatively specify this is as  NULL.
内部XML文档对象,通常创建newXMLDoc的。这是用来作为主机文件的新节点将创建这个文件的一部分。如果一个人想创建节点没有内部文件祖先的,也可以指定这是NULL。


Details

详细信息----------Details----------

This creates a collection of functions that manipulate a shared state to build and maintain an XML tree in C-level code.
这创建了一个集合的功能,操作共享的状态来建立和维护一个XML树中C-级别的代码。


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

An object of class XMLInternalDOM that extends XMLOutputStream and has the same interface (i.e. “methods”) as xmlOutputBuffer  and xmlOutputDOM. Each object has methods for  adding a new XML tag,  closing a tag, adding an XML comment, and retrieving the contents of the tree.
对象的类XMLInternalDOM扩展XMLOutputStream的xmlOutputBuffer和xmlOutputDOM具有相同的接口(即“办法”)。每个对象具有用于添加一个新的XML标记,结束标签,添加一个XML注释,并检索树中的内容的方法。


参数:addTag
create a new tag at the current position, optionally leaving it as the active open tag to which new nodes will be added as children
在当前位置创建一个新的标签,可以选择把它当作新的节点将被添加为儿童主动打开标签


参数:closeTag
close the currently active tag making its parent the active element into which new nodes will be added.
关闭当前活动的标签其父活跃的元素将被添加到新的节点。


参数:addComment
add an XML comment node as a child of the active node in the document.
作为一个孩子的主动节点在文档中添加一个XML注释节点。


参数:value
retrieve an object representing the  XML tree. See saveXML to serialize the contents of the tree.
检索一个对象,该对象表示的XML树。 saveXML的树序列化的内容。


参数:add
degenerate method in this context.
在此上下文中的退化的方法。


注意----------Note----------

This is an early version of this function and I need to iron out some
这是一个早期版本的这个功能,我需要消除一些


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


Duncan Temple Lang



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



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

saveXML newXMLDoc newXMLNode xmlOutputBuffer xmlOutputDOM
saveXMLnewXMLDocnewXMLNodexmlOutputBufferxmlOutputDOM


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



z = xmlTree("people", namespaces = list(r = "http://www.r-project.org"))
z$setNamespace("r")

z$addNode("person", attrs = c(id = "123"), close = FALSE)
  z$addNode("firstname", "Duncan")
  z$addNode("surname", "Temple Lang")
  z$addNode("title", "Associate Professor")
  z$addNode("expertize", close = FALSE)
     z$addNode("topic", "Data Technologies")
     z$addNode("topic", "Programming Language Design")
     z$addNode("topic", "Parallel Computing")
     z$addNode("topic", "Data Visualization")
     z$addNode("topic", "Meta-Computing")
     z$addNode("topic", "Inter-system interfaces")
  z$closeTag()
  z$addNode("address", "4210 Mathematical Sciences Building, UC Davis")
z$closeTag()

  tr <- xmlTree("CDataTest")
  tr$addTag("top", close=FALSE)
  tr$addCData("x <- list(1, a='&amp;');\nx[[2]]")
  tr$addPI("S", "plot(1:10)")
  tr$closeTag()
  cat(saveXML(tr$value()))


  f = tempfile()
  saveXML(tr, f, encoding = "UTF-8")


  # Creating a node[创建一个节点]
x = rnorm(3)
z = xmlTree("r:data", namespaces = c(r = "http://www.r-project.org"))
z$addNode("numeric", attrs = c("r:length" = length(x)))


  # shows namespace prefix on an attribute, and different from the one on the node.[显示属性的命名空间前缀,并从一个节点上的不同。]
  z = xmlTree()
z$addNode("r:data",  namespace = c(r = "http://www.r-project.org", omg = "http://www.omegahat.org"), close = FALSE)
x = rnorm(3)
z$addNode("r:numeric", attrs = c("omg:length" = length(x)))


z = xmlTree("examples")
z$addNode("example", namespace = list(r = "http://www.r-project.org"), close = FALSE)
z$addNode("code", "mean(rnorm(100))", namespace = "r")


x = summary(rnorm(1000))
d = xmlTree()
d$addNode("table", close = FALSE)

d$addNode("tr", .children = sapply(names(x), function(x) d$addNode("th", x)))
d$addNode("tr", .children = sapply(x, function(x) d$addNode("td", format(x))))

d$closeNode()
cat(saveXML(d))

# Dealing with DTDs and system and public identifiers for DTDs.[与DTD,系统和公共标识符的DTD的处理。]
# Just doctype[只是DOCTYPE]
za = xmlTree("people", dtd = "people")
# no public element[没有公共元素]
zb = xmlTree("people", dtd = c("people", "", "http://www.omegahat.org/XML/types.dtd"))
# public and system[公共和系统]
zc = xmlTree("people", dtd = c("people", "//a//b//c//d", "http://www.omegahat.org/XML/types.dtd"))




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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-11-24 15:46 , Processed in 0.022577 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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