xml - Undefined namespace xml2 in R -
i'm learning how use r parse xml, , i'm trying use hadley's wickham's xml2
package parse tei xml text document, located here (warning: zipped file, particular 1 i'm trying parse given in code below). i'm trying head around how namespaces work in package (i can't make sense of documentation particular text i'm using). xml
package, following:
library("xml") crisis <- xmlparse("data/crisis130_22.2.tei.xml") all_divs <- getnodeset(crisis, "//def:div", namespaces=c(def = "http://www.tei-c.org/ns/1.0"))
i can't figure out how xml2
, however. either inherits(x, "xml_document") not true
error or in node_find_all(x$node, x$doc, xpath = xpath, nsmap = ns) : undefined namespace prefix [1219]
error. tried:
library("xml2") crisis2 <- read_xml("data/crisis130_22.2.tei.xml") # check see whether tei url present xml_ns(crisis2) all_divs2 <- xml_find_all(crisis2, "//div", xml_ns(crisis2)) # gives empty list all_divs <- xml_find_all(crisis2, "/def:div", xml_ns(crisis2)) # undefined namespace error
i know new package, know how use namespaces in it?
ok, figured out myself, thought post here instead of deleting question.
library("xml2") crisis2 <- read_xml("data/crisis130_22.2.tei.xml") all_divs <- xml_find_all(crisis2, "//d1:div", xml_ns(crisis2))
in retrospect, guess answer obvious, but, said, thought post solution here in case helps in future.
Comments
Post a Comment