[rkward-cvs] SF.net SVN: rkward:[3916] trunk/rkward/packages/XiMpLe
m-eik at users.sourceforge.net
m-eik at users.sourceforge.net
Sun Oct 9 20:36:04 UTC 2011
Revision: 3916
http://rkward.svn.sourceforge.net/rkward/?rev=3916&view=rev
Author: m-eik
Date: 2011-10-09 20:36:04 +0000 (Sun, 09 Oct 2011)
Log Message:
-----------
XiMpLe: added new option "tidy" to the paste functions, so "<" and ">" in text or attribute values don't mess up the generated XML
Modified Paths:
--------------
trunk/rkward/packages/XiMpLe/ChangeLog
trunk/rkward/packages/XiMpLe/DESCRIPTION
trunk/rkward/packages/XiMpLe/R/XiMpLe-internal.R
trunk/rkward/packages/XiMpLe/R/XiMpLe-package.R
trunk/rkward/packages/XiMpLe/R/pasteXMLNode.R
trunk/rkward/packages/XiMpLe/R/pasteXMLTag.R
trunk/rkward/packages/XiMpLe/R/pasteXMLTree.R
trunk/rkward/packages/XiMpLe/inst/CITATION
trunk/rkward/packages/XiMpLe/man/XiMpLe-package.Rd
trunk/rkward/packages/XiMpLe/man/pasteXMLNode.Rd
trunk/rkward/packages/XiMpLe/man/pasteXMLTag.Rd
trunk/rkward/packages/XiMpLe/man/pasteXMLTree.Rd
Modified: trunk/rkward/packages/XiMpLe/ChangeLog
===================================================================
--- trunk/rkward/packages/XiMpLe/ChangeLog 2011-10-09 17:38:10 UTC (rev 3915)
+++ trunk/rkward/packages/XiMpLe/ChangeLog 2011-10-09 20:36:04 UTC (rev 3916)
@@ -1,5 +1,9 @@
ChangeLog for package XiMpLe
+## 0.03-6 (2011-10-09)
+ - added "tidy" option to the paste functions, which is TRUE by default since "<" and ">" are
+ invalid in attributes and text anyway
+
## 0.03-5 (2011-10-07)
- fixed tree parsing bug (in rare cases, comment and CDATA entries caused parsing to choke on
empty lines)
Modified: trunk/rkward/packages/XiMpLe/DESCRIPTION
===================================================================
--- trunk/rkward/packages/XiMpLe/DESCRIPTION 2011-10-09 17:38:10 UTC (rev 3915)
+++ trunk/rkward/packages/XiMpLe/DESCRIPTION 2011-10-09 20:36:04 UTC (rev 3916)
@@ -19,8 +19,8 @@
URL: http://rkward.sourceforge.net
Authors at R: c(person(given="Meik", family="Michalke",
email="meik.michalke at hhu.de", role=c("aut", "cre")))
-Version: 0.03-5
-Date: 2011-10-07
+Version: 0.03-6
+Date: 2011-10-09
Collate:
'XiMpLe.node-class.R'
'XiMpLe.doc-class.R'
Modified: trunk/rkward/packages/XiMpLe/R/XiMpLe-internal.R
===================================================================
--- trunk/rkward/packages/XiMpLe/R/XiMpLe-internal.R 2011-10-09 17:38:10 UTC (rev 3915)
+++ trunk/rkward/packages/XiMpLe/R/XiMpLe-internal.R 2011-10-09 20:36:04 UTC (rev 3916)
@@ -103,6 +103,18 @@
paste(rep(by, level-1), collapse="")
} ## end function indent()
+## function xml.tidy()
+# replace special character < and > from attributes or text values
+# with harmless entities
+xml.tidy <- function(text){
+ if(is.character(text)){
+ tidy.text <- gsub("<", "<", gsub(">", ">", text))
+ } else {
+ return(text)
+ }
+ return(tidy.text)
+} ## function xml.tidy()
+
## function lookupAttrName()
# takes the original input element names and returns
# the according XML attribute name
@@ -117,11 +129,15 @@
## function pasteXMLAttr()
# pastes all attributes in a nicely readable way
-pasteXMLAttr <- function(attr=NULL, tag=NULL, level=1, rename=NULL, shine=2, indent.by="\t"){
+pasteXMLAttr <- function(attr=NULL, tag=NULL, level=1, rename=NULL, shine=2, indent.by="\t", tidy=FALSE){
if(is.null(attr)){
return("")
} else {}
+ if(isTRUE(tidy)){
+ attr <- sapply(attr, xml.tidy)
+ } else {}
+
new.indent <- ifelse(shine > 1, indent(level+1, by=indent.by), "")
new.attr <- ifelse(shine > 1, "\n", " ")
Modified: trunk/rkward/packages/XiMpLe/R/XiMpLe-package.R
===================================================================
--- trunk/rkward/packages/XiMpLe/R/XiMpLe-package.R 2011-10-09 17:38:10 UTC (rev 3915)
+++ trunk/rkward/packages/XiMpLe/R/XiMpLe-package.R 2011-10-09 20:36:04 UTC (rev 3916)
@@ -3,8 +3,8 @@
#' \tabular{ll}{
#' Package: \tab XiMpLe\cr
#' Type: \tab Package\cr
-#' Version: \tab 0.03-5\cr
-#' Date: \tab 2011-10-07\cr
+#' Version: \tab 0.03-6\cr
+#' Date: \tab 2011-10-09\cr
#' Depends: \tab R (>= 2.9.0),methods\cr
#' Enhances: \tab rkward\cr
#' Encoding: \tab UTF-8\cr
Modified: trunk/rkward/packages/XiMpLe/R/pasteXMLNode.R
===================================================================
--- trunk/rkward/packages/XiMpLe/R/pasteXMLNode.R 2011-10-09 17:38:10 UTC (rev 3915)
+++ trunk/rkward/packages/XiMpLe/R/pasteXMLNode.R 2011-10-09 20:36:04 UTC (rev 3916)
@@ -9,14 +9,16 @@
#' \item{2}{Nodes will be indented and each attribute gets a new line.}
#' }
#' @param indent.by A charachter string defining how indentation should be done. Defaults to tab.
+#' @param tidy Logical, if \code{TRUE} the special characters "<" and ">" will be replaced with the entities
+#' "<" and "gt;" in attributes and text values.
#' @include XiMpLe.node-class.R
#' @export
-pasteXMLNode <- function(node, level=1, shine=1, indent.by="\t"){
+pasteXMLNode <- function(node, level=1, shine=1, indent.by="\t", tidy=TRUE){
if(!inherits(node, "XiMpLe.node")){
if(inherits(node, "XiMpLe.doc")){
# hand over to pasteXMLTree()
warning("'node' is of class XiMpLe.doc, called pasteXMLTree() instead.")
- return(pasteXMLTree(obj=node, shine=shine, indent.by=indent.by))
+ return(pasteXMLTree(obj=node, shine=shine, indent.by=indent.by, tidy=tidy))
} else {
stop(simpleError("'node' must be of class XiMpLe.node!"))
}
@@ -37,7 +39,7 @@
if(length(node.chld) > 0){
node.chld <- paste(unlist(sapply(node.chld, function(this.node){
- return(pasteXMLNode(this.node, level=(level + 1), shine=shine, indent.by=indent.by))})), collapse="", sep="")
+ return(pasteXMLNode(this.node, level=(level + 1), shine=shine, indent.by=indent.by, tidy=tidy))})), collapse="", sep="")
node.empty <- FALSE
} else {
node.chld <- NULL
@@ -48,11 +50,14 @@
if(length(node.val) > 0){
node.empty <- FALSE
if(nchar(node.val) > 0){
+ if(isTRUE(tidy)){
+ node.val <- sapply(node.val, xml.tidy)
+ } else {}
node.chld <- paste(new.indent, paste(node.val, collapse=" "), new.node, sep="")
} else {}
} else {}
- pasted.node <- pasteXMLTag(node.name, attr=node.attr, child=node.chld, empty=node.empty, level=level, allow.empty=TRUE, rename=NULL, shine=shine, indent.by=indent.by)
+ pasted.node <- pasteXMLTag(node.name, attr=node.attr, child=node.chld, empty=node.empty, level=level, allow.empty=TRUE, rename=NULL, shine=shine, indent.by=indent.by, tidy=tidy)
return(pasted.node)
}
Modified: trunk/rkward/packages/XiMpLe/R/pasteXMLTag.R
===================================================================
--- trunk/rkward/packages/XiMpLe/R/pasteXMLTag.R 2011-10-09 17:38:10 UTC (rev 3915)
+++ trunk/rkward/packages/XiMpLe/R/pasteXMLTag.R 2011-10-09 20:36:04 UTC (rev 3916)
@@ -20,10 +20,12 @@
#' \item{2}{Nodes will be indented and each attribute gets a new line.}
#' }
#' @param indent.by A charachter string defining how indentation should be done. Defaults to tab.
+#' @param tidy Logical, if \code{TRUE} the special characters "<" and ">" will be replaced with the entities
+#' "<" and "gt;" in attribute values.
#' @export
-pasteXMLTag <- function(tag, attr=NULL, child=NULL, empty=TRUE, level=1, allow.empty=FALSE, rename=NULL, shine=2, indent.by="\t"){
+pasteXMLTag <- function(tag, attr=NULL, child=NULL, empty=TRUE, level=1, allow.empty=FALSE, rename=NULL, shine=2, indent.by="\t", tidy=TRUE){
# what attributes do we have?
- all.attributes <- pasteXMLAttr(attr, tag=tag, level=level, rename=rename, shine=shine, indent.by=indent.by)
+ all.attributes <- pasteXMLAttr(attr, tag=tag, level=level, rename=rename, shine=shine, indent.by=indent.by, tidy=tidy)
# probaly don't produce empty tags
if(!isTRUE(allow.empty) & is.null(all.attributes)){
return("")
Modified: trunk/rkward/packages/XiMpLe/R/pasteXMLTree.R
===================================================================
--- trunk/rkward/packages/XiMpLe/R/pasteXMLTree.R 2011-10-09 17:38:10 UTC (rev 3915)
+++ trunk/rkward/packages/XiMpLe/R/pasteXMLTree.R 2011-10-09 20:36:04 UTC (rev 3916)
@@ -8,14 +8,16 @@
#' \item{2}{Nodes will be indented and each attribute gets a new line.}
#' }
#' @param indent.by A charachter string defining how indentation should be done. Defaults to tab.
+#' @param tidy Logical, if \code{TRUE} the special characters "<" and ">" will be replaced with the entities
+#' "<" and "gt;" in attributes and text values.
#' @include XiMpLe.doc-class.R
#' @export
-pasteXMLTree <- function(obj, shine=1, indent.by="\t"){
+pasteXMLTree <- function(obj, shine=1, indent.by="\t", tidy=TRUE){
if(!inherits(obj, "XiMpLe.doc")){
if(inherits(obj, "XiMpLe.node")){
# hand over to pasteXMLNode()
warning("'node' is of class XiMpLe.node, called pasteXMLNode() instead.")
- return(pasteXMLNode(node=obj, shine=shine, indent.by=indent.by))
+ return(pasteXMLNode(node=obj, shine=shine, indent.by=indent.by, tidy=tidy))
} else {
stop(simpleError("'obj' must be of class XiMpLe.doc!"))
}
@@ -27,7 +29,7 @@
tree.nodes <- slot(obj, "children")
if(any(nchar(unlist(tree.xml)) > 0)) {
- doc.xml <- pasteXMLTag("?xml", attr=tree.xml, child=NULL, empty=TRUE, level=1, allow.empty=FALSE, rename=NULL, shine=min(1, shine), indent.by=indent.by)
+ doc.xml <- pasteXMLTag("?xml", attr=tree.xml, child=NULL, empty=TRUE, level=1, allow.empty=FALSE, rename=NULL, shine=min(1, shine), indent.by=indent.by, tidy=tidy)
doc.xml <- gsub("/>", "\\?>", doc.xml)
} else {
doc.xml <- ""
@@ -48,7 +50,7 @@
if(length(tree.nodes) > 0) {
doc.nodes <- paste(unlist(sapply(tree.nodes, function(this.node){
- return(pasteXMLNode(this.node, level=1, shine=shine, indent.by=indent.by))})), collapse="", sep="")
+ return(pasteXMLNode(this.node, level=1, shine=shine, indent.by=indent.by, tidy=tidy))})), collapse="", sep="")
} else {
doc.nodes <- ""
}
Modified: trunk/rkward/packages/XiMpLe/inst/CITATION
===================================================================
--- trunk/rkward/packages/XiMpLe/inst/CITATION 2011-10-09 17:38:10 UTC (rev 3915)
+++ trunk/rkward/packages/XiMpLe/inst/CITATION 2011-10-09 20:36:04 UTC (rev 3916)
@@ -2,12 +2,12 @@
title="XiMpLe: A simple XML tree parser and generator",
author="Meik Michalke",
year="2011",
- note="(Version 0.03-5)",
+ note="(Version 0.03-6)",
url="http://rkward.sourceforge.net",
textVersion =
paste("Michalke, M. (2011). ",
- "XiMpLe: A simple XML tree parser and generator (Version 0.03-5). ",
+ "XiMpLe: A simple XML tree parser and generator (Version 0.03-6). ",
"Available from http://rkward.sourceforge.net",
sep=""),
Modified: trunk/rkward/packages/XiMpLe/man/XiMpLe-package.Rd
===================================================================
--- trunk/rkward/packages/XiMpLe/man/XiMpLe-package.Rd 2011-10-09 17:38:10 UTC (rev 3915)
+++ trunk/rkward/packages/XiMpLe/man/XiMpLe-package.Rd 2011-10-09 20:36:04 UTC (rev 3916)
@@ -8,8 +8,8 @@
}
\details{
\tabular{ll}{ Package: \tab XiMpLe\cr Type: \tab
- Package\cr Version: \tab 0.03-5\cr Date: \tab
- 2011-10-07\cr Depends: \tab R (>= 2.9.0),methods\cr
+ Package\cr Version: \tab 0.03-6\cr Date: \tab
+ 2011-10-09\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://rkward.sourceforge.net\cr }
Modified: trunk/rkward/packages/XiMpLe/man/pasteXMLNode.Rd
===================================================================
--- trunk/rkward/packages/XiMpLe/man/pasteXMLNode.Rd 2011-10-09 17:38:10 UTC (rev 3915)
+++ trunk/rkward/packages/XiMpLe/man/pasteXMLNode.Rd 2011-10-09 20:36:04 UTC (rev 3916)
@@ -3,7 +3,7 @@
\title{Paste an XML node from a XiMpLe.node object}
\usage{
pasteXMLNode(node, level = 1, shine = 1, indent.by =
- "\t")
+ "\t", tidy = TRUE)
}
\arguments{
\item{node}{An object of class \code{XiMpLe.node}.}
@@ -18,6 +18,10 @@
\item{indent.by}{A charachter string defining how
indentation should be done. Defaults to tab.}
+
+ \item{tidy}{Logical, if \code{TRUE} the special
+ characters "<" and ">" will be replaced with the entities
+ "<" and "gt;" in attributes and text values.}
}
\description{
Paste an XML node from a XiMpLe.node object
Modified: trunk/rkward/packages/XiMpLe/man/pasteXMLTag.Rd
===================================================================
--- trunk/rkward/packages/XiMpLe/man/pasteXMLTag.Rd 2011-10-09 17:38:10 UTC (rev 3915)
+++ trunk/rkward/packages/XiMpLe/man/pasteXMLTag.Rd 2011-10-09 20:36:04 UTC (rev 3916)
@@ -4,7 +4,7 @@
\usage{
pasteXMLTag(tag, attr = NULL, child = NULL, empty = TRUE,
level = 1, allow.empty = FALSE, rename = NULL, shine = 2,
- indent.by = "\t")
+ indent.by = "\t", tidy = TRUE)
}
\arguments{
\item{tag}{Character string, name of the XML tag.}
@@ -37,6 +37,10 @@
\item{indent.by}{A charachter string defining how
indentation should be done. Defaults to tab.}
+
+ \item{tidy}{Logical, if \code{TRUE} the special
+ characters "<" and ">" will be replaced with the entities
+ "<" and "gt;" in attribute values.}
}
\description{
Creates a whole XML tag with attributes and, if it is a
Modified: trunk/rkward/packages/XiMpLe/man/pasteXMLTree.Rd
===================================================================
--- trunk/rkward/packages/XiMpLe/man/pasteXMLTree.Rd 2011-10-09 17:38:10 UTC (rev 3915)
+++ trunk/rkward/packages/XiMpLe/man/pasteXMLTree.Rd 2011-10-09 20:36:04 UTC (rev 3916)
@@ -2,7 +2,8 @@
\alias{pasteXMLTree}
\title{Paste an XML tree structure from a XiMpLe.doc object}
\usage{
- pasteXMLTree(obj, shine = 1, indent.by = "\t")
+ pasteXMLTree(obj, shine = 1, indent.by = "\t", tidy =
+ TRUE)
}
\arguments{
\item{obj}{An object of class \code{XiMpLe.doc}.}
@@ -15,6 +16,10 @@
\item{indent.by}{A charachter string defining how
indentation should be done. Defaults to tab.}
+
+ \item{tidy}{Logical, if \code{TRUE} the special
+ characters "<" and ">" will be replaced with the entities
+ "<" and "gt;" in attributes and text values.}
}
\description{
Paste an XML tree structure from a XiMpLe.doc object
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