swh:1:snp:7d9f1bc35e120776766db9334626062f837c20ad
Tip revision: c5d145673d3feb15d9c872aea3be3647966d1a4f authored by ORPHANED on 19 June 2017, 11:43:32 UTC
version 3.98-1.9
version 3.98-1.9
Tip revision: c5d1456
fixNS.R
MissingNS = c(gating = "http://www.crap.org",
'data-type' = "http://www.morecrap.org")
fixXMLNamespaces =
#
# call as
# dd = fixXMLNamespaces("~/v75_step6.wsp", .namespaces = MissingNS)
# or
# dd = fixXMLNamespaces("~/v75_step6.wsp", gating = "http://www.crap.org", 'data-type' = "http://www.morecrap.org")
#
function(doc = "~/v75_step6.wsp", ..., .namespaces = list(...))
{
# collect the error messages
e = xmlErrorCumulator(, FALSE)
doc = xmlParse(doc, error = e)
if(length(e) == 0)
return(doc)
# find the ones that refer to prefixes that are not defined
ns = grep("^Namespace prefix .* not defined", unique(environment(e)$messages), value = TRUE)
ns = unique(gsub("Namespace prefix ([^ ]+) .*", "\\1", ns))
# now set those name spaces on the root of the document
if(is(.namespaces, "list"))
.namespaces = structure(as.character(unlist(.namespaces)), names = names(.namespaces))
uris = .namespaces[ns]
if(length(uris)) {
mapply(function(id, uri)
newXMLNamespace(xmlRoot(doc), uri, id),
names(uris), uris)
xmlParse(saveXML(doc), asText = TRUE)
} else
doc
}