Get definitions of any namespaces defined in this XML node
xmlNamespaceDefinitions.RdIf the given node has any namespace definitions declared within it,
i.e. of the form 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.
Usage
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)Arguments
- x
the
XMLNodeobject in which to find any namespace definitions- addNames
a logical indicating whether to compute the names for the elements in the resulting list. The names are convenient, but one can avoid the (very small) overhead of computing these with this parameter.
- doc
the XMLInternalDocument object obtained from a call to
xmlParse- recursive
a logical value indicating whether to extract the namespace definitions for just this node (
FALSE) or all of the descendant nodes as well (TRUE). If this isTRUE, all the namespace definitions are collected into a single "flat" list and so there may be duplicate names.- simplify
a logical value. If this is
TRUE, a character vector of prefix-URI pairs is returned. This can be used directly in calls to functions such asxpathApplyandgetNodeSet. The default value ofFALSEreturns a list of name space definitions which also identify whether the definition is local to the particular node or inherited from an ancestor.- ns
the collection of namespaces. This is typically omitted but can be specified if it has been computed in an earlier step.
- ...
additional parameters for methods
Value
A list with as many elements as there are namespace definitions.
Each element is an object of class XMLNameSpace,
containing fields giving the local identifier, the associated defining
URI and a logical value indicating whether the definition is local to
this node.
The name of each element is the prefix or alias used for that
namespace definition, i.e. the value of the id field in the
namespace definition. For default namespaces, i.e. those that have no
prefix/alias, the name is "".
Examples
f = system.file("exampleData", "longitudinalData.xml", package = "XML")
n = xmlRoot(xmlTreeParse(f))
xmlNamespaceDefinitions(n)
#> $rs
#> $id
#> [1] "rs"
#>
#> $uri
#> [1] "http://www.omegahat.net/RSXML"
#>
#> $local
#> [1] TRUE
#>
#> attr(,"class")
#> [1] "XMLNamespaceDefinition"
#>
#> $lgtdl
#> $id
#> [1] "lgtdl"
#>
#> $uri
#> [1] "http://www.r-project.org/XML/lgtdl"
#>
#> $local
#> [1] TRUE
#>
#> attr(,"class")
#> [1] "XMLNamespaceDefinition"
#>
#> attr(,"class")
#> [1] "XMLNamespaceDefinitions"
xmlNamespaceDefinitions(n, recursive = TRUE)
#> $rs
#> $id
#> [1] "rs"
#>
#> $uri
#> [1] "http://www.omegahat.net/RSXML"
#>
#> $local
#> [1] TRUE
#>
#> attr(,"class")
#> [1] "XMLNamespaceDefinition"
#>
#> $lgtdl
#> $id
#> [1] "lgtdl"
#>
#> $uri
#> [1] "http://www.r-project.org/XML/lgtdl"
#>
#> $local
#> [1] TRUE
#>
#> attr(,"class")
#> [1] "XMLNamespaceDefinition"
#>
#> attr(,"class")
#> [1] "XMLNamespaceDefinitions"
# Now using internal nodes.
f = system.file("exampleData", "namespaces.xml", package = "XML")
doc = xmlInternalTreeParse(f)
n = xmlRoot(doc)
xmlNamespaceDefinitions(n)
#> [[1]]
#> $id
#> [1] ""
#>
#> $uri
#> [1] "http://www.omegahat.net"
#>
#> $local
#> [1] TRUE
#>
#> attr(,"class")
#> [1] "XMLNamespaceDefinition"
#>
#> $omegahat
#> $id
#> [1] "omegahat"
#>
#> $uri
#> [1] "http://www.omegahat.net"
#>
#> $local
#> [1] TRUE
#>
#> attr(,"class")
#> [1] "XMLNamespaceDefinition"
#>
#> $r
#> $id
#> [1] "r"
#>
#> $uri
#> [1] "http://www.r-project.org"
#>
#> $local
#> [1] TRUE
#>
#> attr(,"class")
#> [1] "XMLNamespaceDefinition"
#>
#> attr(,"class")
#> [1] "XMLNamespaceDefinitions"
xmlNamespaceDefinitions(n, recursive = TRUE)
#> [[1]]
#> $id
#> [1] ""
#>
#> $uri
#> [1] "http://www.omegahat.net"
#>
#> $local
#> [1] TRUE
#>
#> attr(,"class")
#> [1] "XMLNamespaceDefinition"
#>
#> $omegahat
#> $id
#> [1] "omegahat"
#>
#> $uri
#> [1] "http://www.omegahat.net"
#>
#> $local
#> [1] TRUE
#>
#> attr(,"class")
#> [1] "XMLNamespaceDefinition"
#>
#> $r
#> $id
#> [1] "r"
#>
#> $uri
#> [1] "http://www.r-project.org"
#>
#> $local
#> [1] TRUE
#>
#> attr(,"class")
#> [1] "XMLNamespaceDefinition"
#>
#> $c
#> $id
#> [1] "c"
#>
#> $uri
#> [1] "http://www.c.org"
#>
#> $local
#> [1] TRUE
#>
#> attr(,"class")
#> [1] "XMLNamespaceDefinition"
#>
#> attr(,"class")
#> [1] "XMLNamespaceDefinitions"