I'm trying to create an xml .. running the following code, the first doc is created .. but the last line directly kill rstudio .. (R session aborted ..)
library(XML)
# CREATE XML FILE
doc = newXMLDoc()
root = newXMLNode("Envelope", doc = doc)
# WRITE XML NODES AND DATA
mvNode = newXMLNode("Header/", parent = root)
mvNode = newXMLNode("Body", parent = root)
print(doc)
# CREATE XML FILE
doc = newXMLDoc(namespaces = list("http://schemas.xmlsoap.org/soap/envelope/"))
root = newXMLNode("soapenv:Envelope", doc = doc)
# WRITE XML NODES AND DATA
mvNode = newXMLNode("soapenv:Header", parent = root)
mvNode = newXMLNode("soapenv:Body", parent = root)
Can someone confirm ? Can someone explain this issue ?
CodePudding user response:
Consider using the fixNamespaces
argument, specifying dummy=FALSE
to have child nodes use ancestor namespaces which appears to resolve this interesting issue (which also occurs in RGui).
Also, the namespaces
argument (plural) in newXMLDoc
does not appear to work with subsequent newXMLNode
. Such an argument may relate to the nodes added within its method with ...
which I cannot get to work. Therefore define namespace at the root or highest needed level for namespace.
# CREATE XML FILE
doc <- newXMLDoc()
root <- newXMLNode(
"soap:Envelope",
doc = doc,
namespace = c(soap="http://schemas.xmlsoap.org/soap/envelope/"),
fixNamespaces = c(dummy=FALSE, default=TRUE)
)
# WRITE XML NODES AND DATA
mvHeader <- newXMLNode(
"soap:Header", parent = root, fixNamespaces = c(dummy=FALSE, default=TRUE)
)
mvBody <- newXMLNode(
"soap:Body", parent = root, fixNamespaces = c(dummy=FALSE, default=TRUE)
)
print(doc)
# <?xml version="1.0"?>
# <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
# <soap:Header/>
# <soap:Body/>
# </soap:Envelope>