Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

getLineNumber

Determine the location - file & line number of an (internal) XML node


Description

The getLineNumber function is used to query the location of an internal/C-level XML node within its original "file". This gives us the line number. getNodeLocation gives both the line number and the name of the file in which the node is located, handling XInclude files in a top-level document and identifying the included file, as appropriate. getNodePosition returns a simplified version of getNodeLocation, combining the file and line number into a string and ignoring the XPointer component.

This is useful when we identify a node with a particular charactestic and want to view/edit the original document, e.g. when authoring an Docbook article.

Usage

getLineNumber(node, ...)
getNodeLocation(node, recursive = TRUE, fileOnly = FALSE)

Arguments

node

the node whose location or line number is of interest

...

additional parameters for methods should they be defined.

recursive

a logical value that controls whether the full path of the nested includes is returned or just the path in the immediate XInclude element.

fileOnly

a logical value which if TRUE means that only the name of the file is returned, and not the xpointer attribute or line number .

Value

getLineNumber returns an integer. getNodeLocation returns a list with two elements - file and line which are a character string and the integer line number.

For text nodes, the line number is taken from the previous sibling nodes or the parent node.

Author(s)

Duncan Temple Lang

References

libxml2

See Also

Examples

f = system.file("exampleData", "xysize.svg", package = "XML")
doc = xmlParse(f)
e = getNodeSet(doc, "//ellipse")
sapply(e, getLineNumber)

XML

Tools for Parsing and Generating XML Within R and S-Plus

v3.99-0.10
BSD_3_clause + file LICENSE
Authors
CRAN Team [ctb, cre] (de facto maintainer since 2013), Duncan Temple Lang [aut] (<https://orcid.org/0000-0003-0159-1546>), Tomas Kalibera [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.