[rkward-cvs] SF.net SVN: rkward:[4183] trunk/rkward/packages/XiMpLe
m-eik at users.sourceforge.net
m-eik at users.sourceforge.net
Thu Mar 15 16:41:01 UTC 2012
Revision: 4183
http://rkward.svn.sourceforge.net/rkward/?rev=4183&view=rev
Author: m-eik
Date: 2012-03-15 16:41:00 +0000 (Thu, 15 Mar 2012)
Log Message:
-----------
node() now also works with XML nodes, and still fighting with pasteXMLNode()...
Modified Paths:
--------------
trunk/rkward/packages/XiMpLe/ChangeLog
trunk/rkward/packages/XiMpLe/DESCRIPTION
trunk/rkward/packages/XiMpLe/R/XMLNode.R
trunk/rkward/packages/XiMpLe/R/XiMpLe-package.R
trunk/rkward/packages/XiMpLe/R/node.R
trunk/rkward/packages/XiMpLe/R/pasteXMLNode.R
trunk/rkward/packages/XiMpLe/R/pasteXMLTag.R
trunk/rkward/packages/XiMpLe/inst/NEWS.Rd
trunk/rkward/packages/XiMpLe/man/XiMpLe-package.Rd
trunk/rkward/packages/XiMpLe/man/node.Rd
Modified: trunk/rkward/packages/XiMpLe/ChangeLog
===================================================================
--- trunk/rkward/packages/XiMpLe/ChangeLog 2012-03-15 16:12:53 UTC (rev 4182)
+++ trunk/rkward/packages/XiMpLe/ChangeLog 2012-03-15 16:41:00 UTC (rev 4183)
@@ -1,5 +1,9 @@
ChangeLog for package XiMpLe
+changes in version 0.03-12 (2012-03-15)
+ - node() now also works with single XiMpLe.node objects (not only full trees)
+ - fixed dropped text value if node also had child nodes in pasteXMLNode()
+
changes in version 0.03-11 (2012-03-14)
- added functions XMLNode() and XMLTree() as constructor functions for XML nodes and trees.
- added opton "object" to parseXMLTree(), to be able to parse XML trees not only from files, but also character vectors
Modified: trunk/rkward/packages/XiMpLe/DESCRIPTION
===================================================================
--- trunk/rkward/packages/XiMpLe/DESCRIPTION 2012-03-15 16:12:53 UTC (rev 4182)
+++ trunk/rkward/packages/XiMpLe/DESCRIPTION 2012-03-15 16:41:00 UTC (rev 4183)
@@ -18,7 +18,7 @@
Authors at R: c(person(given="Meik", family="Michalke",
email="meik.michalke at hhu.de", role=c("aut", "cre")))
Version: 0.03-11
-Date: 2012-03-14
+Date: 2012-03-15
Collate:
'XiMpLe.node-class.R'
'XiMpLe.doc-class.R'
Modified: trunk/rkward/packages/XiMpLe/R/XMLNode.R
===================================================================
--- trunk/rkward/packages/XiMpLe/R/XMLNode.R 2012-03-15 16:12:53 UTC (rev 4182)
+++ trunk/rkward/packages/XiMpLe/R/XMLNode.R 2012-03-15 16:41:00 UTC (rev 4183)
@@ -17,8 +17,12 @@
XMLNode <- function(name, ..., attrs=NULL, namespace="", namespaceDefinitions=NULL, .children=list(...)){
- if(identical(.children, list(""))){
+ # text node?
+ if(identical(name, "") & all(unlist(lapply(.children, is.character)))){
all.children <- list()
+ value <- paste(..., sep=" ")
+ } else if(identical(.children, list(""))){
+ all.children <- list()
value <- ""
} else {
# remove NULLs
@@ -43,4 +47,4 @@
value=value)
return(newNode)
-}
\ No newline at end of file
+}
Modified: trunk/rkward/packages/XiMpLe/R/XiMpLe-package.R
===================================================================
--- trunk/rkward/packages/XiMpLe/R/XiMpLe-package.R 2012-03-15 16:12:53 UTC (rev 4182)
+++ trunk/rkward/packages/XiMpLe/R/XiMpLe-package.R 2012-03-15 16:41:00 UTC (rev 4183)
@@ -4,7 +4,7 @@
#' Package: \tab XiMpLe\cr
#' Type: \tab Package\cr
#' Version: \tab 0.03-11\cr
-#' Date: \tab 2012-03-14\cr
+#' Date: \tab 2012-03-15\cr
#' Depends: \tab R (>= 2.9.0),methods\cr
#' Enhances: \tab rkward\cr
#' Encoding: \tab UTF-8\cr
Modified: trunk/rkward/packages/XiMpLe/R/node.R
===================================================================
--- trunk/rkward/packages/XiMpLe/R/node.R 2012-03-15 16:12:53 UTC (rev 4182)
+++ trunk/rkward/packages/XiMpLe/R/node.R 2012-03-15 16:41:00 UTC (rev 4183)
@@ -2,7 +2,7 @@
#'
#' This method can be used to get parts of a parsed XML tree object, or to fill it with new values.
#'
-#' @param obj An object of class \code{XiMpLe.doc}
+#' @param obj An object of class \code{XiMpLe.doc} or \code{XiMpLe.node}.
#' @param node A list of node names (or their numeric values), where each element is
#' the child of its previous element. duplicate matches will be returned as a list.
#' @param what A character string, must be a valid slot name of class \code{XiMpLe.node}, like
@@ -28,15 +28,29 @@
#' @export
setGeneric("node", function(obj, node=list(), what=NULL, cond.attr=NULL, cond.value=NULL, element=NULL){standardGeneric("node")})
+# define class union to make life easier
+setClassUnion("XiMpLe.XML", members=c("XiMpLe.node", "XiMpLe.doc"))
+
setMethod("node",
- signature(obj="XiMpLe.doc"),
+ signature(obj="XiMpLe.XML"),
function(obj, node=list(), what=NULL, cond.attr=NULL, cond.value=NULL, element=NULL){
+ # check top level if this is a node, not a tree
+ if(inherits(obj, "XiMpLe.node")){
+ got.this <- identical(slot(obj, "name"), node[[1]])
+ if(!isTRUE(got.this)){
+ # apparently, this node doesn't exist
+ stop(simpleError(paste("Can't find node ", node[[1]], " in ", sQuote(deparse(substitute(obj))), "!", sep="")))
+ } else {
+ # remove first element in list node
+ node[[1]] <- NULL
+ }
+ } else {}
result.node.path <- "obj"
for (this.node in node){
for (this.path in result.node.path){
this.node.part <- eval(parse(text=this.path))
- got.this <- names(this.node.part at children) %in% this.node
+ got.this <- lapply(slot(this.node.part, "children"), function(this.child){slot(this.child, "name")}) %in% this.node
if(!any(got.this)){
# apparently, this node doesn't exist
stop(simpleError(paste("Can't find node ", sQuote(this.node), " in ", sQuote(deparse(substitute(obj))), "!", sep="")))
@@ -101,6 +115,14 @@
result <- unlist(lapply(result.node.path, function(this.path){
this.node <- eval(parse(text=this.path))
results <- slot(this.node, what)
+ # special case: text values can either be directly in the value slot of a node,
+ # or in a pseudo tag as a child node, so we check both
+ if(identical(what, "value")){
+ for (this.child in slot(this.node, "children")){
+ if(identical(slot(this.child, "name"), "") & isTRUE(nchar(slot(this.child, "value")) > 0))
+ results <- c(results, slot(this.child, "value"))
+ }
+ } else {}
if(!is.null(element)){
results <- results[element]
} else {}
@@ -131,7 +153,7 @@
setGeneric("node<-", function(obj, node=list(), what=NULL, cond.attr=NULL, cond.value=NULL, element=NULL, value){standardGeneric("node<-")})
setMethod("node<-",
- signature(obj="XiMpLe.doc"),
+ signature(obj="XiMpLe.XML"),
function(obj, node=list(), what=NULL, cond.attr=NULL, cond.value=NULL, element=NULL, value){
# get path to node in object
Modified: trunk/rkward/packages/XiMpLe/R/pasteXMLNode.R
===================================================================
--- trunk/rkward/packages/XiMpLe/R/pasteXMLNode.R 2012-03-15 16:12:53 UTC (rev 4182)
+++ trunk/rkward/packages/XiMpLe/R/pasteXMLNode.R 2012-03-15 16:41:00 UTC (rev 4183)
@@ -53,7 +53,7 @@
if(isTRUE(tidy)){
node.val <- sapply(node.val, xml.tidy)
} else {}
- node.chld <- paste(paste(node.val, collapse=" "), sep="")
+ node.chld <- paste(node.chld, paste(new.indent, node.val, new.node, collapse=" "), sep="")
} else {}
} else {}
Modified: trunk/rkward/packages/XiMpLe/R/pasteXMLTag.R
===================================================================
--- trunk/rkward/packages/XiMpLe/R/pasteXMLTag.R 2012-03-15 16:12:53 UTC (rev 4182)
+++ trunk/rkward/packages/XiMpLe/R/pasteXMLTag.R 2012-03-15 16:41:00 UTC (rev 4183)
@@ -70,13 +70,14 @@
new.attr <- ifelse((length(attr) > 1), new.attr, "")
new.attr.indent <- ifelse((length(attr) > 1), new.attr.indent, "")
new.cmmt.indent <- ifelse((length(attr) > 1), new.cmmt.indent, "")
+ val.indent <- ifelse(shine > 1, indent(level + 1, by=indent.by), "")
# empty decides whether this is a empty tag or a pair of start and end tags
if(isTRUE(empty)){
full.tag <- paste(new.indent, "<", tag, attr.space, new.attr, new.cmmt.indent, all.attributes, new.attr, new.attr.indent, " />", new.node, sep="")
} else {
full.tag <- paste(
new.indent, "<", tag, attr.space, new.attr, new.cmmt.indent, all.attributes, new.attr, new.attr.indent, ">", new.node,
- if(!is.null(child)){child},
+ if(!is.null(child)){paste(val.indent, child, sep="")},
new.indent, "</", tag, ">", new.node, sep="")
}
}
Modified: trunk/rkward/packages/XiMpLe/inst/NEWS.Rd
===================================================================
--- trunk/rkward/packages/XiMpLe/inst/NEWS.Rd 2012-03-15 16:12:53 UTC (rev 4182)
+++ trunk/rkward/packages/XiMpLe/inst/NEWS.Rd 2012-03-15 16:41:00 UTC (rev 4183)
@@ -1,6 +1,12 @@
\name{NEWS}
\title{News for Package 'XiMpLe'}
\encoding{UTF-8}
+\section{Changes in XiMpLe version 0.03-12 (2012-03-15)}{
+ \itemize{
+ \item \code{node()} now also works with single XiMpLe.node objects (not only full trees)
+ \item fixed dropped text value if node also had child nodes in \code{pasteXMLNode()}
+ }
+}
\section{Changes in XiMpLe version 0.03-11 (2012-03-14)}{
\itemize{
\item added functions \code{XMLNode()} and \code{XMLTree()} as constructor functions for XML nodes and trees.
Modified: trunk/rkward/packages/XiMpLe/man/XiMpLe-package.Rd
===================================================================
--- trunk/rkward/packages/XiMpLe/man/XiMpLe-package.Rd 2012-03-15 16:12:53 UTC (rev 4182)
+++ trunk/rkward/packages/XiMpLe/man/XiMpLe-package.Rd 2012-03-15 16:41:00 UTC (rev 4183)
@@ -9,7 +9,7 @@
\details{
\tabular{ll}{ Package: \tab XiMpLe\cr Type: \tab
Package\cr Version: \tab 0.03-11\cr Date: \tab
- 2012-03-14\cr Depends: \tab R (>= 2.9.0),methods\cr
+ 2012-03-15\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 }
Modified: trunk/rkward/packages/XiMpLe/man/node.Rd
===================================================================
--- trunk/rkward/packages/XiMpLe/man/node.Rd 2012-03-15 16:12:53 UTC (rev 4182)
+++ trunk/rkward/packages/XiMpLe/man/node.Rd 2012-03-15 16:41:00 UTC (rev 4183)
@@ -5,7 +5,8 @@
\alias{node,XiMpLe.doc-method}
\title{Extract/manipulate a node or parts of it from an XML tree}
\arguments{
- \item{obj}{An object of class \code{XiMpLe.doc}}
+ \item{obj}{An object of class \code{XiMpLe.doc} or
+ \code{XiMpLe.node}.}
\item{node}{A list of node names (or their numeric
values), where each element is the child of its previous
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the rkward-tracker
mailing list