[rkward-cvs] SF.net SVN: rkward-code:[4755] trunk/rkward/packages/XiMpLe/R/ zzz_is_get_utils.R

m-eik at users.sf.net m-eik at users.sf.net
Fri May 24 13:52:47 UTC 2013


Revision: 4755
          http://sourceforge.net/p/rkward/code/4755
Author:   m-eik
Date:     2013-05-24 13:52:46 +0000 (Fri, 24 May 2013)
Log Message:
-----------
XiMpLe: added option for XMLScan() to always return results as a list.

Modified Paths:
--------------
    trunk/rkward/packages/XiMpLe/R/zzz_is_get_utils.R

Modified: trunk/rkward/packages/XiMpLe/R/zzz_is_get_utils.R
===================================================================
--- trunk/rkward/packages/XiMpLe/R/zzz_is_get_utils.R	2013-05-23 18:15:22 UTC (rev 4754)
+++ trunk/rkward/packages/XiMpLe/R/zzz_is_get_utils.R	2013-05-24 13:52:46 UTC (rev 4755)
@@ -36,8 +36,9 @@
 #' Another special method can scan a node/document tree object for appearances of nodes with a particular name:
 #'
 #' \itemize{
-#'		\item{\code{XMLScan()}: }{get/set the XML nodes by name (recursively searches slot \code{name} of both classes
-#'			\code{XiMpLe.node} and  \code{XiMpLe.doc})}
+#'		\item{\code{XMLScan(obj, name, as.list=FALSE)}: }{get/set the XML nodes by name (recursively searches slot \code{name} of both classes
+#'			\code{XiMpLe.node} and  \code{XiMpLe.doc}). If \code{as.list=TRUE} allways returns a list (or NULL), otherwise if exactly one result is found,
+#'			it will be returned as as single \code{XiMpLe.node}.}
 #' }
 #'
 #' @param obj An object of class \code{XiMpLe.node} or \code{XiMpLe.doc}
@@ -317,7 +318,7 @@
 ## scan a tree for appearances of nodes
 #' @rdname XMLGetters-methods
 #' @exportMethod XMLScan
-setGeneric("XMLScan", function(obj, name) standardGeneric("XMLScan"))
+setGeneric("XMLScan", function(obj, name, as.list=FALSE) standardGeneric("XMLScan"))
 
 # internal helper function
 find.nodes <- function(nodes, nName){
@@ -340,13 +341,13 @@
 #' @include XiMpLe.node-class.R
 setMethod("XMLScan",
 	signature=signature(obj="XiMpLe.node"),
-	function(obj, name){
+	function(obj, name, as.list=FALSE){
 		node.list <- find.nodes(
 			nodes=child.list(obj),
 			nName=name)
 		if(identical(node.list, list())){
 			return(NULL)
-		} else if(length(node.list) == 1){
+		} else if(length(node.list) == 1 && !isTRUE(as.list)){
 			return(node.list[[1]])
 		} else {
 			return(node.list)
@@ -361,13 +362,13 @@
 #' @include XiMpLe.doc-class.R
 setMethod("XMLScan",
 	signature=signature(obj="XiMpLe.doc"),
-	function(obj, name){
+	function(obj, name, as.list=FALSE){
 		node.list <- find.nodes(
 			nodes=XMLChildren(obj),
 			nName=name)
 		if(identical(node.list, list())){
 			return(NULL)
-		} else if(length(node.list) == 1){
+		} else if(length(node.list) == 1 && !isTRUE(as.list)){
 			return(node.list[[1]])
 		} else {
 			return(node.list)





More information about the rkward-tracker mailing list