saveXML(XML)
saveXML()所属R语言包:XML
Output internal XML Tree
输出内部XML树
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Methods for writing the representation of an XML tree to a string or file. Originally this was intended to be used only for DOMs (Document Object Models) stored in internal memory created via xmlTree, but methods for XMLNode, XMLInternalNode and XMLOutputStream objects (and others) allow it to be generic for different representations of the XML tree.
写的XML树中表示为一个字符串或文件的方法。原来这是为了只用于存储在内存中的DOM(文档对象模型)通过xmlTree的方法,但XMLNode,XMLInternalNode和XMLOutputStream对象(其他人的问题)允许它是通用的XML树的不同的表述。
Note that the indentation when writing an internal C-based node (XMLInternalNode) may not be as expected if there are text nodes within the node.
请注意,写入时的内部基于C的的节点(XMLInternalNode)的压痕可能不能如预期的,如果有文本节点内的节点。
Also, not all the parameters are meaningful for all methods. For example, compressing when writing to a string is not supported.
此外,并非所有的参数都是有意义的所有方法。例如,不支持压缩时,写入到一个字符串。
用法----------Usage----------
saveXML(doc, file=NULL, compression=0, indent=TRUE, prefix = '<?xml version="1.0"?>\n',
doctype = NULL, encoding = getEncoding(doc), ...)
## S3 method for class 'XMLInternalDocument'
saveXML(doc, file=NULL, compression=0, indent=TRUE, prefix = '<?xml version="1.0"?>\n',
doctype = NULL, encoding = getEncoding(doc), ...)
## S3 method for class 'XMLInternalDOM'
saveXML(doc, file=NULL, compression=0, indent=TRUE, prefix = '<?xml version="1.0"?>\n',
doctype = NULL, encoding = getEncoding(doc), ...)
## S3 method for class 'XMLNode'
saveXML(doc, file=NULL, compression=0, indent=TRUE, prefix = '<?xml version="1.0"?>\n',
doctype = NULL, encoding = getEncoding(doc), ...)
## S3 method for class 'XMLOutputStream'
saveXML(doc, file=NULL, compression=0, indent=TRUE, prefix = '<?xml version="1.0"?>\n',
doctype = NULL, encoding = getEncoding(doc), ...)
参数----------Arguments----------
参数:doc
the document object representing the XML document.
表示XML文档的文档对象。
参数:file
the name of the file to which the contents of the XML nodes will be serialized.
的XML节点中的内容将被序列化到其中的文件的名称。
参数:compression
an integer value between 0 and 9 indicating the level of compression to use when saving the file. Higher values indicate increased compression and hence smaller files at the expense of computational time to do the compression and decompression.
0到9之间的整数值,表示保存文件时使用的压缩级别。增加值越高,表示压缩,因此在计算时间为代价的压缩与解压缩的更小的文件。
参数:indent
a logical value indicating whether to indent the nested nodes when serializing to the stream.
一个逻辑值,该值指示是否缩进嵌套的节点时,序列化到流中。
参数:prefix
a string that is written to the stream/connection before the XML is output. If this is NULL, it is ignored. This allows us to put the XML introduction/preamble at the beginning of the document while allowing it to be omitted when we are outputting multiple "documents" within a single stream.
输出一个字符串,该字符串被写入之前的XML流/连接。如果这是NULL,则忽略它。这使我们能够把XML介绍/序言开头的文件,而允许它被省略,当我们在一个单一的数据流输出多个“文件”。
参数:doctype
an object identifying the elements for the DOCTYPE in the output. This can be a string or an object of class Doctype.
对象识别的DOCTYPE在输出的元素。这可以是一个字符串或对象类Doctype。
参数:encoding
a string indicating which encoding style to use. This is currently ignored except in the method in Sxslt for saving a document generated by applying an XSL style sheet to an XML document.
一个字符串,表示使用的编码方式。这是目前被忽略,但Sxslt所产生的一个XSL样式表应用到XML文档保存文档的方法。
参数:...
extra parameters for specific methods
具体方法为额外的参数
Details
详细信息----------Details----------
One can create an internal XML tree (or DOM) using newXMLDoc and newXMLNode. saveXML allows one to generate a textual representation of that DOM in human-readable and reusable XML format. saveXML is a generic function that allows one to call the rendering operation with either the top-level node of the DOM or of the document object (of class XMLInternalDocument that is used to accumulate the nodes and with which the developer adds nodes.
人们可以创建一个内部XML树(DOM),使用newXMLDoc和newXMLNode。 saveXML允许一个产生在人类可读和可重复使用的XML格式的文本表示,DOM。 saveXML是一个通用的功能,可以让一个叫渲染操作的顶级节点的DOM文档对象(共类XMLInternalDocument,用于积累的节点和开发人员添加节点。
值----------Value----------
If file is not specified, the result is a character string containing the resulting XML content. If file is passed in the call,
file如果没有被指定,其结果是一个字符串,其中包含生成的XML内容。如果file是在调用中传递,
(作者)----------Author(s)----------
Duncan Temple Lang
参考文献----------References----------
<h3>See Also</h3> <code>newXMLDoc</code> <code>newXMLNode</code> <code>xmlOutputBuffer</code> <code>xmlOutputDOM</code>
实例----------Examples----------
b = newXMLNode("bob")
saveXML(b)
f = tempfile()
saveXML(b, f)
doc = xmlInternalTreeParse(f)
saveXML(doc)
con <- xmlOutputDOM()
con$addTag("author", "Duncan Temple Lang")
con$addTag("address", close=FALSE)
con$addTag("office", "2C-259")
con$addTag("street", "Mountain Avenue.")
con$addTag("phone", close=FALSE)
con$addTag("area", "908", attrs=c(state="NJ"))
con$addTag("number", "582-3217")
con$closeTag() # phone[检测]
con$closeTag() # address[地址]
saveXML(con$value(), file="out.xml")
# Work with entities[与实体]
f = system.file("exampleData", "test1.xml", package = "XML")
doc = xmlRoot(xmlTreeParse(f))
outFile = tempfile()
saveXML(doc, outFile)
alt = xmlRoot(xmlTreeParse(outFile))
if(! identical(doc, alt) )
stop("Problems handling entities!")
con = textConnection("test1.xml", "w")
saveXML(doc, con)
close(con)
alt = get("test1.xml")
identical(doc, alt)
x = newXMLNode("a", "some text", newXMLNode("c", "sub text"), "more text")
cat(saveXML(x), "\n")
cat(as(x, "character"), "\n")
# Showing the prefix parameter[显示prefix参数]
doc = newXMLDoc()
n = newXMLNode("top", doc = doc)
b = newXMLNode("bar", parent = n)
# suppress the <?xml ...?>[抑制<?XML ...>]
saveXML(doc, prefix = character())
# put our own comment in[把我们自己的评论]
saveXML(doc, prefix = "<!-- This is an alternative prefix -->")
# or use a comment node.[或使用意见节点。]
saveXML(doc, prefix = newXMLCommentNode("This is an alternative prefix"))
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|