xmlToList(XML)
xmlToList()所属R语言包:XML
Convert an XML node/document to a more R-like list
转换XML节点/文件到R-列表
译者:生物统计家园网 机器人LoveR
描述----------Description----------
This function is an early and simple approach to converting an XML node or document into a more typical R list containing the data values directly (rather than as XML nodes). It is useful for dealing with data that is returned from REST requests or other Web queries or generally when parsing XML and wanting to be able to access the content as elements in a list indexed by the name of the node. For example, if given a node of the form <x> <a>text</a> <b foo="1"/> <c bar="me"> <d>a phrase</d> </c> </x> We would end up with a list with elements named "a", "b" and "c". "a" would be the string "text", b would contain the named character vector c(foo = "1") (i.e. the attributes) and "c" would contain the list with two elements named "d" and ".attrs". The element corresponding to "d" is a character vector with the single element "a phrase". The ".attrs" element of the list is the character vector of attributes from the node <c>...</c>.
此功能是一个早期和简单的方法来转换为XML到一个更典型的R列表,其中包含的数据值(而不是作为XML节点)的节点或文件。它是用于解析XML时,希望能够访问的内容作为索引节点的名称列表中的元素,则返回,从REST请求或其他Web查询或一般的数据处理。例如,如果给定一个节点的形式 c(foo = "1") <a>text</a> <b foo="1"/> <c bar="me"> <d>a phrase</d> </c> </x> 我们将最终命名为“A”,“B”和“C”的元素的列表。 “a”将是字符串“文本”,b都包含命名的字符向量<c>...</c>(即属性)和的“c”将包含列表有两个元素的命名为“d”的“ 。ATTRS“。至“d”相对应的元素是与单一的元素“的短语”一个字符矢量。的“。的ATTRS”元素列表中的字符的属性节点<X>向量。
用法----------Usage----------
xmlToList(node, addAttributes = TRUE, simplify = FALSE)
参数----------Arguments----------
参数:node
the XML node or document to be converted to an R list. This can be an "internal" or C-level node (i.e. XMLInternalNode-class) or a regular R-level node (either XMLNode-class or XMLHashNode).
XML节点或文件被转换为一个R列表。这可能是一个“内部”或C级的节点(即XMLInternalNode-class)或定期R-级节点(XMLNode-class或XMLHashNode)。
参数:addAttributes
a logical value which controls whether the attributes of an empty node are added to the
一个空的节点的属性是否被添加到一个逻辑值,其控制
参数:simplify
a logical value that controls whether we collapse the list to a vector if the elements all have a common compatible type. Basically, this controls whether we use sapply or lapply.
一逻辑值,控制是否倍数列表到一个向量的元素都有一个共同的兼容型。基本上,这个控件,我们是否使用sapply或lapply。
值----------Value----------
A list whose elements correspond to the children of the top-level nodes.
一个列表,其元素对应的顶级节点的孩子。
(作者)----------Author(s)----------
Duncan Temple Lang
参见----------See Also----------
xmlTreeParse getNodeSet and xpathApply xmlRoot, xmlChildren, xmlApply, [[, etc. for accessing the content of XML nodes.
xmlTreeParsegetNodeSet和xpathApplyxmlRoot,xmlChildren,xmlApply,[[,等来访问XML节点的内容。
实例----------Examples----------
tt =
'<x>
<a>text</a>
<b foo="1"/>
<c bar="me">
<d>a phrase</d>
</c>
</x>'
doc = xmlParse(tt)
xmlToList(doc)
# use an R-level node representation[使用R-级节点表示]
doc = xmlTreeParse(tt)
xmlToList(doc)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|