
Last chance! 50% off unlimited learning
Sale ends in
xmlns:myNamespace="http://www.myNS.org"
,
xmlNamespaceDefinitions
provides access to these definitions.
While they appear in the XML node in the document as attributes,
they are treated differently by the parser and so do not show up
in the nodes attributes via xmlAttrs
. getDefaultNamespace
is used to get the default namespace
for the top-level node in a document.
The recursive
parameter allows one to conveniently find all the namespace
definitions in a document or sub-tree without having to examine the file.
This can be useful when working with XPath queries via
getNodeSet
.
xmlNamespaceDefinitions(x, addNames = TRUE, recursive = FALSE, simplify = FALSE, ...)
xmlNamespaces(x, addNames = TRUE, recursive = FALSE, simplify = FALSE, ...)
getDefaultNamespace(doc, ns = xmlNamespaceDefinitions(doc, simplify = simplify), simplify = FALSE)
XMLNode
object in which to find any namespace
definitionsxmlParse
FALSE
)
or all of the descendant nodes as well (TRUE
).
If this is TRUE
, all the namespace definitions are
collected into a single "flat" list and so there may be duplicate
names.
TRUE
,
a character vector of prefix-URI pairs is returned.
This can be used directly in calls to functions such as
xpathApply
and getNodeSet
.
The default value of FALSE
returns a list
of name space definitions which also identify
whether the definition is local to the particular node or inherited
from an ancestor.
id
field in the
namespace definition. For default namespaces, i.e. those that have no
prefix/alias, the name is ""
.
xmlTreeParse
xmlAttrs
xmlGetAttr
f = system.file("exampleData", "longitudinalData.xml", package = "XML")
n = xmlRoot(xmlTreeParse(f))
xmlNamespaceDefinitions(n)
xmlNamespaceDefinitions(n, recursive = TRUE)
# Now using internal nodes.
f = system.file("exampleData", "namespaces.xml", package = "XML")
doc = xmlInternalTreeParse(f)
n = xmlRoot(doc)
xmlNamespaceDefinitions(n)
xmlNamespaceDefinitions(n, recursive = TRUE)
Run the code above in your browser using DataLab