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

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

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

                                        A virtual base class defining methods for SAX parsing
                                         SAX解析虚拟基类中定义方法

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

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

This is a degenerate virtual class which others are expected to sub-class  when they want to use S4 methods as handler functions for SAX-based XML parsing. The idea is that one can pass both i)  a collection of handlers to xmlEventParse which are simply  the generic functions for the different SAX actions, and ii) a suitable object to maintain state across the different SAX calls. This is used to perform the method dispatching to get the appropriate behavior for the action. Each of these methods is expected to return the updated state object and the SAX parser will pass this in the next callback.
这是一个退化的虚拟类,预计到子类时,要使用S4基于SAX的XML解析处理函数方法。我们的想法是,我们可以通过两个i)处理程序的集合xmlEventParse这是简单的通用功能为不同的SAX行动,及ii)一个合适的对象来保持状态在不同的SAX检测。这是用来执行方法调度的行动得到适当的行为。这些方法返回更新后的状态对象,SAX解析器将通过在未来的回调。

We define this class here so that we can provide default methods for each of the different handler actions. This allows other programmers to define new classes to maintain state that are sub-class of SAXState and then they do not have to implement methods for each of the different handlers.
这里我们定义这个类,这样我们就可以采取不同的处理措施提供了默认的方法。这可以让其他程序员定义新类的子类SAXState“,然后他们不必执行每个不同的处理方法,以保持状态。


类对象----------Objects from the Class----------

A virtual Class: No objects may be created from it.
可能会从它创建一个虚拟类:没有对象。


方法----------Methods----------




comment.SAX signature(content = "ANY", .state = "SAXState"): ...
comment.SAX signature(content = "ANY", .state = "SAXState")...




endElement.SAX signature(name = "ANY", .state = "SAXState"): ...
endElement.SAX signature(name = "ANY", .state = "SAXState")...




entityDeclaration.SAX signature(name = "ANY", base = "ANY", sysId = "ANY", publicId = "ANY", notationName = "ANY", .state = "SAXState"): ...
entityDeclaration.SAX signature(name = "ANY", base = "ANY", sysId = "ANY", publicId = "ANY", notationName = "ANY", .state = "SAXState")...




processingInstruction.SAX signature(target = "ANY", content = "ANY", .state = "SAXState"): ...
processingInstruction.SAX signature(target = "ANY", content = "ANY", .state = "SAXState")...




startElement.SAX signature(name = "ANY", atts = "ANY", .state = "SAXState"): ...
startElement.SAX signature(name = "ANY", atts = "ANY", .state = "SAXState")...




text.SAX signature(content = "ANY", .state = "SAXState"): ...
text.SAX signature(content = "ANY", .state = "SAXState")...


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


Duncan Temple Lang



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

<h3>See Also</h3>   <code>xmlEventParse</code>

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



# For each element in the document, grab the node name[对于文档中的每个元素,抢节点名称]
# and increment the count in an vector for this name.[在一个向量,这个名字和递增计数。]

# We define an S4 class named ElementNameCounter which[我们定义一个S4的命名ElementNameCounter的类]
# holds the vector of frequency counts for the node names.[持有向量的频率计数的节点名称。]

setClass("ElementNameCounter",
             representation(elements = "integer"), contains = "SAXState")

# Define a method for handling the opening/start of any XML node[定义的方法处理任何XML节点的开/启动]
# in the SAX streams.[在SAX流。]

setMethod("startElement.SAX",  c(.state = "ElementNameCounter"),
           function(name, atts, .state = NULL) {

             if(name %in% names(.state@elements))
                 .state@elements[name] = as.integer(.state@elements[name] + 1)
             else
                 .state@elements[name] = as.integer(1)
             .state
           })

filename = system.file("exampleData", "eurofxref-hist.xml.gz", package = "XML")

# Parse the file, arranging to have our startElement.SAX method invoked.[解析文件,安排有我们的startElement.SAX调用的方法。]
z = xmlEventParse(filename, genericSAXHandlers(), state = new("ElementNameCounter"), addContext = FALSE)

z@elements

  # Get the contents of all the comments in a character vector.[获取一个字符向量中的所有注释的内容。]

setClass("MySAXState",
             representation(comments = "character"), contains = "SAXState")

setMethod("comment.SAX",  c(.state = "MySAXState"),
           function(content, .state = NULL) {
             cat("comment.SAX called for MySAXState\n")
             .state@comments <- c(.state@comments, content)
             .state
           })

filename = system.file("exampleData", "charts.svg", package = "XML")
st = new("MySAXState")
z = xmlEventParse(filename, genericSAXHandlers(useDotNames = TRUE), state = st)
z@comments



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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-11-24 14:51 , Processed in 0.098394 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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