[rkward-cvs] SF.net SVN: rkward:[4176] trunk/rkward/packages/XiMpLe

m-eik at users.sourceforge.net m-eik at users.sourceforge.net
Tue Mar 13 23:49:56 UTC 2012


Revision: 4176
          http://rkward.svn.sourceforge.net/rkward/?rev=4176&view=rev
Author:   m-eik
Date:     2012-03-13 23:49:55 +0000 (Tue, 13 Mar 2012)
Log Message:
-----------
added constructor functions XMLNode() and XMLTree()

Modified Paths:
--------------
    trunk/rkward/packages/XiMpLe/ChangeLog
    trunk/rkward/packages/XiMpLe/DESCRIPTION
    trunk/rkward/packages/XiMpLe/NAMESPACE
    trunk/rkward/packages/XiMpLe/R/XiMpLe-internal.R
    trunk/rkward/packages/XiMpLe/R/XiMpLe-package.R
    trunk/rkward/packages/XiMpLe/R/XiMpLe.doc-class.R
    trunk/rkward/packages/XiMpLe/R/pasteXMLNode.R
    trunk/rkward/packages/XiMpLe/inst/NEWS.Rd
    trunk/rkward/packages/XiMpLe/man/XiMpLe-package.Rd

Added Paths:
-----------
    trunk/rkward/packages/XiMpLe/R/XMLNode.R
    trunk/rkward/packages/XiMpLe/R/XMLTree.R
    trunk/rkward/packages/XiMpLe/man/XMLNode.Rd
    trunk/rkward/packages/XiMpLe/man/XMLTree.Rd

Modified: trunk/rkward/packages/XiMpLe/ChangeLog
===================================================================
--- trunk/rkward/packages/XiMpLe/ChangeLog	2012-03-13 16:16:21 UTC (rev 4175)
+++ trunk/rkward/packages/XiMpLe/ChangeLog	2012-03-13 23:49:55 UTC (rev 4176)
@@ -1,6 +1,7 @@
 ChangeLog for package XiMpLe
 
 changes in version 0.03-11 (2012-03-13)
+  - 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
   - output of internal function XML.single.tags() has no colname any more
   - text values of nodes are no longer followed by an empty newline in pasteXMLNode()

Modified: trunk/rkward/packages/XiMpLe/DESCRIPTION
===================================================================
--- trunk/rkward/packages/XiMpLe/DESCRIPTION	2012-03-13 16:16:21 UTC (rev 4175)
+++ trunk/rkward/packages/XiMpLe/DESCRIPTION	2012-03-13 23:49:55 UTC (rev 4176)
@@ -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-13
+Date: 2012-03-14
 Collate:
     'XiMpLe.node-class.R'
     'XiMpLe.doc-class.R'
@@ -32,3 +32,5 @@
     'XiMpLe-internal.R'
     'XiMpLe-internal.roxy.all.R'
     'XiMpLe-package.R'
+    'XMLNode.R'
+    'XMLTree.R'

Modified: trunk/rkward/packages/XiMpLe/NAMESPACE
===================================================================
--- trunk/rkward/packages/XiMpLe/NAMESPACE	2012-03-13 16:16:21 UTC (rev 4175)
+++ trunk/rkward/packages/XiMpLe/NAMESPACE	2012-03-13 23:49:55 UTC (rev 4176)
@@ -7,4 +7,6 @@
 export(pasteXMLNode)
 export(pasteXMLTag)
 export(pasteXMLTree)
+export(XMLNode)
+export(XMLTree)
 import(methods)

Added: trunk/rkward/packages/XiMpLe/R/XMLNode.R
===================================================================
--- trunk/rkward/packages/XiMpLe/R/XMLNode.R	                        (rev 0)
+++ trunk/rkward/packages/XiMpLe/R/XMLNode.R	2012-03-13 23:49:55 UTC (rev 4176)
@@ -0,0 +1,44 @@
+#' Constructor function for XiMpLe.node objects
+#' 
+#' Can be used to create XML nodes.
+#' 
+#' @param name Character string, the tag name.
+#' @param ... Optional children for the tag. Must be either objects of class XiMpLe.node or character strings,
+#'		which are treated as simple text values. If this is empty, the tag will be treated as an empty tag. To
+#'		force a closing tag, supply an empty string, i.e. \code{""}.
+#' @param attrs An optional named list of attributes.
+#' @param namespace Currently ignored.
+#' @param namespaceDefinitions Currently ignored.
+#' @param .children Alternative way of specifying children, if you have them already as a list.
+#' @return An object of class XiMpLe.node
+#' @export
+
+XMLNode <- function(name, ..., attrs=NULL, namespace="", namespaceDefinitions=NULL, .children=list(...)){
+
+	if(identical(.children, list(""))){
+		all.children <- list()
+		value <- ""
+	} else {
+		# remove NULLs
+		.children <- .children[unlist(lapply(.children, length) != 0)]
+		# check for text values
+		all.children <- sapply(child.list(.children), function(this.child){
+			if(is.character(this.child)){
+				this.child <- new("XiMpLe.node",
+						name="",
+						value=this.child
+					)
+			} else {}
+			return(this.child)
+		})
+		value <- character()
+	}
+
+	newNode <- new("XiMpLe.node",
+		name=name,
+		attributes=as.list(attrs),
+		children=all.children,
+		value=value)
+
+	return(newNode)
+}
\ No newline at end of file

Added: trunk/rkward/packages/XiMpLe/R/XMLTree.R
===================================================================
--- trunk/rkward/packages/XiMpLe/R/XMLTree.R	                        (rev 0)
+++ trunk/rkward/packages/XiMpLe/R/XMLTree.R	2012-03-13 23:49:55 UTC (rev 4176)
@@ -0,0 +1,45 @@
+#' Constructor function for XiMpLe.doc objects
+#'
+#' Can be used to create full XML trees.
+#'
+#' @param name Character string, the tag name.
+#' @param ... Optional children for the XML tree. Must be either objects of class XiMpLe.node or character strings,
+#'		which are treated as simple text values.
+#' @param xml A named list, XML declaration of the XML tree. Currently just pasted, no checking is done.
+#' @param dtd A named list, doctype definition of the XML tree. Valid elements are \code{doctype}, \code{id} and \code{refer}.
+#'		Currently just pasted, no checking is done.
+#' @param .children Alternative way of specifying children, if you have them already as a list.
+#' @return An object of class XiMpLe.doc
+#' @export
+
+XMLTree <- function(..., xml=NULL, dtd=NULL, .children=list(...)){
+
+	# remove NULLs
+	.children <- .children[unlist(lapply(.children, length) != 0)]
+
+	# check for text values
+	all.children <- sapply(child.list(.children), function(this.child){
+		if(is.character(this.child)){
+			this.child <- new("XiMpLe.node",
+					name="",
+					value=this.child
+				)
+		} else {}
+		return(this.child)
+	})
+
+	if(is.null(xml)){
+		xml <- list()
+	} else {}
+	if(is.null(dtd)){
+		dtd <- list()
+	} else {}
+	
+	newTree <- new("XiMpLe.doc",
+		xml=xml,
+		dtd=dtd,
+		children=all.children
+	)
+
+	return(newTree)
+}
\ No newline at end of file

Modified: trunk/rkward/packages/XiMpLe/R/XiMpLe-internal.R
===================================================================
--- trunk/rkward/packages/XiMpLe/R/XiMpLe-internal.R	2012-03-13 16:16:21 UTC (rev 4175)
+++ trunk/rkward/packages/XiMpLe/R/XiMpLe-internal.R	2012-03-13 23:49:55 UTC (rev 4176)
@@ -1,5 +1,23 @@
 ## internal functions, not exported
 
+
+## function child.list()
+# convenience function to let single children be provided without list()
+child.list <- function(children){
+	if(inherits(children, "XiMpLe.node")){
+		children <- list(children)
+	} else {
+		# if already a list, check if it's a list in a list and get it out
+		if(inherits(children, "list") & length(children) == 1){
+			if(inherits(children[[1]], "list")){
+				children <- children[[1]]
+			} else {}
+		} else {}
+	}
+	return(children)
+} ## end function child.list()
+
+
 ## function split.chars()
 # used to split a character string into parts at each occurrence of the start and end of a regex pattern
 split.chars <- function(txt, pattern, perl=FALSE){

Modified: trunk/rkward/packages/XiMpLe/R/XiMpLe-package.R
===================================================================
--- trunk/rkward/packages/XiMpLe/R/XiMpLe-package.R	2012-03-13 16:16:21 UTC (rev 4175)
+++ trunk/rkward/packages/XiMpLe/R/XiMpLe-package.R	2012-03-13 23:49:55 UTC (rev 4176)
@@ -4,7 +4,7 @@
 #' Package: \tab XiMpLe\cr
 #' Type: \tab Package\cr
 #' Version: \tab 0.03-11\cr
-#' Date: \tab 2012-03-13\cr
+#' Date: \tab 2012-03-14\cr
 #' Depends: \tab R (>= 2.9.0),methods\cr
 #' Enhances: \tab rkward\cr
 #' Encoding: \tab UTF-8\cr

Modified: trunk/rkward/packages/XiMpLe/R/XiMpLe.doc-class.R
===================================================================
--- trunk/rkward/packages/XiMpLe/R/XiMpLe.doc-class.R	2012-03-13 16:16:21 UTC (rev 4175)
+++ trunk/rkward/packages/XiMpLe/R/XiMpLe.doc-class.R	2012-03-13 23:49:55 UTC (rev 4176)
@@ -6,9 +6,9 @@
 # This class is used for objects that are returned by \code{\link[XiMpLe:parseXMLTree]{parseXMLTree}}.
 #
 # @title S4 class XiMpLe.doc
-# @slot file Name of the file.
-# @slot xml XML declaration of the file.
-# @slot dtd Doctype definition of the file.
+# @slot file Character string, Name of the file.
+# @slot xml A named list, XML declaration of the file.
+# @slot dtd A named list, Doctype definition of the file.
 # @slot children A list of objects of class XiMpLe.node, representing the DOM structure of the XML document.
 # @name XiMpLe.doc,-class
 # @aliases XiMpLe.doc-class XiMpLe.doc,-class

Modified: trunk/rkward/packages/XiMpLe/R/pasteXMLNode.R
===================================================================
--- trunk/rkward/packages/XiMpLe/R/pasteXMLNode.R	2012-03-13 16:16:21 UTC (rev 4175)
+++ trunk/rkward/packages/XiMpLe/R/pasteXMLNode.R	2012-03-13 23:49:55 UTC (rev 4176)
@@ -53,7 +53,7 @@
 			if(isTRUE(tidy)){
 				node.val <- sapply(node.val, xml.tidy)
 			} else {}
-			node.chld <- paste(new.indent, paste(node.val, collapse=" "), sep="")
+			node.chld <- paste(paste(node.val, collapse=" "), sep="")
 		} else {}
 	} else {}
 

Modified: trunk/rkward/packages/XiMpLe/inst/NEWS.Rd
===================================================================
--- trunk/rkward/packages/XiMpLe/inst/NEWS.Rd	2012-03-13 16:16:21 UTC (rev 4175)
+++ trunk/rkward/packages/XiMpLe/inst/NEWS.Rd	2012-03-13 23:49:55 UTC (rev 4176)
@@ -3,6 +3,7 @@
 \encoding{UTF-8}
 \section{Changes in XiMpLe version 0.03-11 (2012-03-13)}{
   \itemize{
+    \item added functions \code{XMLNode()} and \code{XMLTree()} as constructor functions for XML nodes and trees.
     \item added opton \code{"object"} to \code{parseXMLTree()}, to be able to parse XML trees not only from files, but also character vectors
     \item output of internal function \code{XML.single.tags()} has no colname any more
     \item text values of nodes are no longer followed by an empty newline in \code{pasteXMLNode()}

Added: trunk/rkward/packages/XiMpLe/man/XMLNode.Rd
===================================================================
--- trunk/rkward/packages/XiMpLe/man/XMLNode.Rd	                        (rev 0)
+++ trunk/rkward/packages/XiMpLe/man/XMLNode.Rd	2012-03-13 23:49:55 UTC (rev 4176)
@@ -0,0 +1,32 @@
+\name{XMLNode}
+\alias{XMLNode}
+\title{Constructor function for XiMpLe.node objects}
+\usage{
+  XMLNode(name, ..., attrs = NULL, namespace = "",
+    namespaceDefinitions = NULL, .children = list(...))
+}
+\arguments{
+  \item{name}{Character string, the tag name.}
+
+  \item{...}{Optional children for the tag. Must be either
+  objects of class XiMpLe.node or character strings, which
+  are treated as simple text values. If this is empty, the
+  tag will be treated as an empty tag. To force a closing
+  tag, supply an empty string, i.e. \code{""}.}
+
+  \item{attrs}{An optional named list of attributes.}
+
+  \item{namespace}{Currently ignored.}
+
+  \item{namespaceDefinitions}{Currently ignored.}
+
+  \item{.children}{Alternative way of specifying children,
+  if you have them already as a list.}
+}
+\value{
+  An object of class XiMpLe.node
+}
+\description{
+  Can be used to create XML nodes.
+}
+

Added: trunk/rkward/packages/XiMpLe/man/XMLTree.Rd
===================================================================
--- trunk/rkward/packages/XiMpLe/man/XMLTree.Rd	                        (rev 0)
+++ trunk/rkward/packages/XiMpLe/man/XMLTree.Rd	2012-03-13 23:49:55 UTC (rev 4176)
@@ -0,0 +1,32 @@
+\name{XMLTree}
+\alias{XMLTree}
+\title{Constructor function for XiMpLe.doc objects}
+\usage{
+  XMLTree(..., xml = NULL, dtd = NULL,
+    .children = list(...))
+}
+\arguments{
+  \item{name}{Character string, the tag name.}
+
+  \item{...}{Optional children for the XML tree. Must be
+  either objects of class XiMpLe.node or character strings,
+  which are treated as simple text values.}
+
+  \item{xml}{A named list, XML declaration of the XML tree.
+  Currently just pasted, no checking is done.}
+
+  \item{dtd}{A named list, doctype definition of the XML
+  tree. Valid elements are \code{doctype}, \code{id} and
+  \code{refer}.  Currently just pasted, no checking is
+  done.}
+
+  \item{.children}{Alternative way of specifying children,
+  if you have them already as a list.}
+}
+\value{
+  An object of class XiMpLe.doc
+}
+\description{
+  Can be used to create full XML trees.
+}
+

Modified: trunk/rkward/packages/XiMpLe/man/XiMpLe-package.Rd
===================================================================
--- trunk/rkward/packages/XiMpLe/man/XiMpLe-package.Rd	2012-03-13 16:16:21 UTC (rev 4175)
+++ trunk/rkward/packages/XiMpLe/man/XiMpLe-package.Rd	2012-03-13 23:49:55 UTC (rev 4176)
@@ -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-13\cr Depends: \tab R (>= 2.9.0),methods\cr
+  2012-03-14\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 }

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