[rkward-cvs] SF.net SVN: rkward-code:[4768] trunk/rkward/packages/XiMpLe
m-eik at users.sf.net
m-eik at users.sf.net
Wed Nov 13 15:29:03 UTC 2013
Revision: 4768
http://sourceforge.net/p/rkward/code/4768
Author: m-eik
Date: 2013-11-13 15:29:02 +0000 (Wed, 13 Nov 2013)
Log Message:
-----------
XiMpLe: adding XMLScanDeep() method (still needs some work...)
Modified Paths:
--------------
trunk/rkward/packages/XiMpLe/ChangeLog
trunk/rkward/packages/XiMpLe/DESCRIPTION
trunk/rkward/packages/XiMpLe/NAMESPACE
trunk/rkward/packages/XiMpLe/R/XiMpLe-package.R
trunk/rkward/packages/XiMpLe/R/zzz_is_get_utils.R
trunk/rkward/packages/XiMpLe/man/XMLGetters-methods.Rd
trunk/rkward/packages/XiMpLe/man/XiMpLe-package.Rd
Modified: trunk/rkward/packages/XiMpLe/ChangeLog
===================================================================
--- trunk/rkward/packages/XiMpLe/ChangeLog 2013-11-11 19:45:49 UTC (rev 4767)
+++ trunk/rkward/packages/XiMpLe/ChangeLog 2013-11-13 15:29:02 UTC (rev 4768)
@@ -1,10 +1,12 @@
ChangeLog for package XiMpLe
-changes in version 0.03-21 (2013-11-11)
+changes in version 0.03-21 (2013-11-13)
added:
- new attribute "as.list" added to XMLScan(), if TRUE forces the return
value to be a list of length 1 (default is still to directly return the
single node).
+ - new method XMLScanDeep() recursively scans for attributes and returns all
+ which were found
changed:
- added a proper GPL notice at the beginning of each R file
Modified: trunk/rkward/packages/XiMpLe/DESCRIPTION
===================================================================
--- trunk/rkward/packages/XiMpLe/DESCRIPTION 2013-11-11 19:45:49 UTC (rev 4767)
+++ trunk/rkward/packages/XiMpLe/DESCRIPTION 2013-11-13 15:29:02 UTC (rev 4768)
@@ -1,7 +1,7 @@
Package: XiMpLe
Type: Package
Title: A simple XML tree parser and generator
-Author: m.eik michalke <meik.michalke at hhu.de>
+Author: m.eik michalke
Maintainer: m.eik michalke <meik.michalke at hhu.de>
Depends:
R (>= 2.9.0),methods
@@ -20,7 +20,7 @@
Authors at R: c(person(given="Meik", family="Michalke",
email="meik.michalke at hhu.de", role=c("aut", "cre")))
Version: 0.03-21
-Date: 2013-05-24
+Date: 2013-11-13
Collate:
'XiMpLe-internal.R'
'XiMpLe.node-class.R'
Modified: trunk/rkward/packages/XiMpLe/NAMESPACE
===================================================================
--- trunk/rkward/packages/XiMpLe/NAMESPACE 2013-11-11 19:45:49 UTC (rev 4767)
+++ trunk/rkward/packages/XiMpLe/NAMESPACE 2013-11-13 15:29:02 UTC (rev 4768)
@@ -20,6 +20,7 @@
exportMethods("XMLName<-")
exportMethods(XMLScan)
exportMethods("XMLScan<-")
+exportMethods(XMLScanDeep)
exportMethods(XMLValue)
exportMethods("XMLValue<-")
export(parseXMLTree)
Modified: trunk/rkward/packages/XiMpLe/R/XiMpLe-package.R
===================================================================
--- trunk/rkward/packages/XiMpLe/R/XiMpLe-package.R 2013-11-11 19:45:49 UTC (rev 4767)
+++ trunk/rkward/packages/XiMpLe/R/XiMpLe-package.R 2013-11-13 15:29:02 UTC (rev 4768)
@@ -1,28 +1,10 @@
-# Copyright 2011-2013 Meik Michalke <meik.michalke at hhu.de>
-#
-# This file is part of the R package XiMpLe.
-#
-# XiMpLe is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# XiMpLe is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with XiMpLe. If not, see <http://www.gnu.org/licenses/>.
-
-
#' A simple XML tree parser and generator.
#'
#' \tabular{ll}{
#' Package: \tab XiMpLe\cr
#' Type: \tab Package\cr
#' Version: \tab 0.03-21\cr
-#' Date: \tab 2013-05-24\cr
+#' Date: \tab 2013-11-13\cr
#' Depends: \tab R (>= 2.9.0),methods\cr
#' Enhances: \tab rkward\cr
#' Encoding: \tab UTF-8\cr
@@ -36,10 +18,10 @@
#' It's not as powerful as the XML package and doesn't aim to be, but for simple XML handling
#' it could be useful. It was originally programmed for RKWard.
#'
-#' @aliases XiMpLe-package XiMpLe
+#' @aliases XiMpLe-package
#' @name XiMpLe-package
#' @docType package
#' @title The XiMpLe Package
-#' @author Meik Michalke \email{meik.michalke@@hhu.de}
+#' @author Meik Michalke
#' @keywords package
NULL
Modified: trunk/rkward/packages/XiMpLe/R/zzz_is_get_utils.R
===================================================================
--- trunk/rkward/packages/XiMpLe/R/zzz_is_get_utils.R 2013-11-11 19:45:49 UTC (rev 4767)
+++ trunk/rkward/packages/XiMpLe/R/zzz_is_get_utils.R 2013-11-13 15:29:02 UTC (rev 4768)
@@ -59,6 +59,12 @@
#' it will be returned as as single \code{XiMpLe.node}.}
#' }
#'
+#' Finally, there is a method to scan for certain values in XiMpLe objects and just list them. For instance, it can be used to
+#' list all instances of a certain attribute type in a document tree:
+#'
+#' \itemize{
+#' \item{\code{XMLScanDeep(obj, find, search="attributes")}: }{returns all found instances of \code{find} in all slots defined by \code{search}.}
+#' }
#' @param obj An object of class \code{XiMpLe.node} or \code{XiMpLe.doc}
#' @seealso
#' \code{\link[XiMpLe:node]{node}},
@@ -461,3 +467,60 @@
return(obj)
}
)
+
+#' @rdname XMLGetters-methods
+#' @exportMethod XMLScanDeep
+setGeneric("XMLScanDeep", function(obj, find=NULL, search="attributes") standardGeneric("XMLScanDeep"))
+
+# internal helper function
+recursiveScan <- function(robj, rfind, rsearch, recResult=list(), result, envID="all"){
+ if(is.XiMpLe.doc(robj)){
+ recResult <- append(recResult, lapply(robj at children, function(this.child){
+ recursiveScan(robj=this.child, rfind=rfind, rsearch=rsearch, recResult=recResult, result=result, envID=envID)
+ }))
+ } else if(is.XiMpLe.node(robj)){
+ attrs <- XMLAttrs(robj)[[rfind]]
+ if(!is.null(attrs)){
+ attrResult <- as.list(result)
+ nodeName <- XMLName(robj)
+ attrResult[[envID]] <- append(attrResult[[envID]], attrs)
+ names(attrResult[[envID]])[length(attrResult[[envID]])] <- nodeName
+ list2env(attrResult, envir=result)
+ } else {}
+ recResult <- append(recResult, lapply(robj at children, function(this.child){
+ recursiveScan(robj=this.child, rfind=rfind, rsearch=rsearch, recResult=recResult, result=result, envID=envID)
+ }))
+ }
+ return(recResult)
+}
+
+#' @rdname XMLGetters-methods
+#' @aliases
+#' XMLScanDeep,-methods
+#' XMLScanDeep,XiMpLe.node-method
+#' @docType methods
+#' @include XiMpLe.node-class.R
+setMethod("XMLScanDeep",
+ signature=signature(obj="XiMpLe.node"),
+ function(obj, find, search){
+ result <- new.env()
+ assign(find, c(), envir=result)
+ recursiveScan(robj=obj, rfind=find, rsearch=search, recResult=list(), result=result, envID=find)
+ return(get(find, envir=result))
+ }
+)
+
+#' @rdname XMLGetters-methods
+#' @aliases
+#' XMLScanDeep,XiMpLe.doc-method
+#' @docType methods
+#' @include XiMpLe.doc-class.R
+setMethod("XMLScanDeep",
+ signature=signature(obj="XiMpLe.doc"),
+ function(obj, find, search){
+ result <- new.env()
+ assign(find, c(), envir=result)
+ recursiveScan(robj=obj, rfind=find, rsearch=search, recResult=list(), result=result, envID=find)
+ return(get(find, envir=result))
+ }
+)
Modified: trunk/rkward/packages/XiMpLe/man/XMLGetters-methods.Rd
===================================================================
--- trunk/rkward/packages/XiMpLe/man/XMLGetters-methods.Rd 2013-11-11 19:45:49 UTC (rev 4767)
+++ trunk/rkward/packages/XiMpLe/man/XMLGetters-methods.Rd 2013-11-13 15:29:02 UTC (rev 4768)
@@ -40,6 +40,10 @@
\alias{XMLName,XiMpLe.node-method}
\alias{XMLScan}
\alias{XMLScan<-}
+\alias{XMLScanDeep}
+\alias{XMLScanDeep,-methods}
+\alias{XMLScanDeep,XiMpLe.doc-method}
+\alias{XMLScanDeep,XiMpLe.node-method}
\alias{XMLScan<-,-methods}
\alias{XMLScan,-methods}
\alias{XMLScan<-,XiMpLe.doc-method}
@@ -93,6 +97,15 @@
returns a list (or NULL), otherwise if exactly one result
is found, it will be returned as as single
\code{XiMpLe.node}.} }
+
+ Finally, there is a method to scan for certain values in
+ XiMpLe objects and just list them. For instance, it can
+ be used to list all instances of a certain attribute type
+ in a document tree:
+
+ \itemize{ \item{\code{XMLScanDeep(obj, find,
+ search="attributes")}: }{returns all found instances of
+ \code{find} in all slots defined by \code{search}.} }
}
\examples{
xmlTestNode <- XMLNode("foo", XMLNode("testchild"))
Modified: trunk/rkward/packages/XiMpLe/man/XiMpLe-package.Rd
===================================================================
--- trunk/rkward/packages/XiMpLe/man/XiMpLe-package.Rd 2013-11-11 19:45:49 UTC (rev 4767)
+++ trunk/rkward/packages/XiMpLe/man/XiMpLe-package.Rd 2013-11-13 15:29:02 UTC (rev 4768)
@@ -1,6 +1,5 @@
\docType{package}
\name{XiMpLe-package}
-\alias{XiMpLe}
\alias{XiMpLe-package}
\title{The XiMpLe Package}
\description{
@@ -9,7 +8,7 @@
\details{
\tabular{ll}{ Package: \tab XiMpLe\cr Type: \tab
Package\cr Version: \tab 0.03-21\cr Date: \tab
- 2013-05-24\cr Depends: \tab R (>= 2.9.0),methods\cr
+ 2013-11-13\cr Depends: \tab R (>= 2.9.0),methods\cr
Enhances: \tab rkward\cr Encoding: \tab UTF-8\cr License:
\tab GPL (>= 3)\cr LazyLoad: \tab yes\cr URL: \tab
http://reaktanz.de/?c=hacking&s=XiMpLe\cr }
@@ -23,7 +22,7 @@
for RKWard.
}
\author{
- Meik Michalke \email{meik.michalke at hhu.de}
+ Meik Michalke
}
\keyword{package}
More information about the rkward-tracker
mailing list