text <\/bar> <\/foo>\") x xml_name(x) xml_children(x) xml_text(x) xml_find_all(x, \".//baz\") h <- read_html(\"Hi !\") h xml_name(h) xml_text(h)"},{"path":"http://xml2.r-lib.org/dev/index.html","id":"compared-to-the-xml-package","dir":"","previous_headings":"","what":"Compared to the XML package","title":"Parse XML","text":"xml2 similar goals XML package. main differences : xml2 takes care memory management . automatically free memory used XML document soon last reference goes away. xml2 simple class hierarchy don’t need think exactly type object , xml2 just right thing. convenient handling namespaces Xpath expressions - see xml_ns() xml_ns_strip() get started.","code":""},{"path":"http://xml2.r-lib.org/dev/index.html","id":"code-of-conduct","dir":"","previous_headings":"","what":"Code of Conduct","title":"Parse XML","text":"Please note xml2 project released Contributor Code Conduct. contributing project, agree abide terms.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/as_list.html","id":null,"dir":"Reference","previous_headings":"","what":"Coerce xml nodes to a list. — as_list","title":"Coerce xml nodes to a list. — as_list","text":"turns XML document (node nodeset) equivalent R list. Note as_list(), .list(): lapply() automatically calls .list() inputs, override default.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/as_list.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Coerce xml nodes to a list. — as_list","text":"","code":"as_list(x, ns = character(), ...)"},{"path":"http://xml2.r-lib.org/dev/reference/as_list.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Coerce xml nodes to a list. — as_list","text":"x document, node, node set. ns Optionally, named vector giving prefix-url pairs, produced xml_ns(). provided, names explicitly qualified ns prefix, .e. element bar defined namespace foo, called foo:bar. (similarly attributes). Default namespaces must given explicit name. ns ignored using xml_name<-() xml_set_name(). ... Needed compatibility generic. Unused.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/as_list.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Coerce xml nodes to a list. — as_list","text":"as_list currently handles four common types children element might : elements, converted lists. Attributes, stored R attributes. Attributes special meanings R (class(), comment(), dim(), dimnames(), names(), row.names() tsp()) escaped '.' Text, stored character vector.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/as_list.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Coerce xml nodes to a list. — as_list","text":"","code":"as_list(read_xml(\" a <\/d>]]><\/c><\/foo>\")) #> $foo #> $foo[[1]] #> [1] \" a \" #> #> $foo$b #> list() #> #> $foo$c #> $foo$c[[1]] #> [1] \"<\/d>\" #> #> #> as_list(read_xml(\" <\/bar> <\/foo>\")) #> $foo #> $foo$bar #> $foo$bar$baz #> list() #> #> #> as_list(read_xml(\"<\/foo>\")) #> $foo #> list() #> attr(,\"id\") #> [1] \"a\" #> as_list(read_xml(\"<\/foo>\")) #> $foo #> $foo$bar #> list() #> attr(,\"id\") #> [1] \"a\" #> #> $foo$bar #> list() #> attr(,\"id\") #> [1] \"b\" #> #>"},{"path":"http://xml2.r-lib.org/dev/reference/as_xml_document.html","id":null,"dir":"Reference","previous_headings":"","what":"Coerce a R list to xml nodes. — as_xml_document","title":"Coerce a R list to xml nodes. — as_xml_document","text":"turns R list equivalent XML document. R lists produce valid XML, particular can one root node child nodes need named (empty) lists. R attributes become XML attributes R names become XML node names.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/as_xml_document.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Coerce a R list to xml nodes. — as_xml_document","text":"","code":"as_xml_document(x, ...)"},{"path":"http://xml2.r-lib.org/dev/reference/as_xml_document.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Coerce a R list to xml nodes. — as_xml_document","text":"x document, node, node set. ... Needed compatibility generic. Unused.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/as_xml_document.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Coerce a R list to xml nodes. — as_xml_document","text":"","code":"as_xml_document(list(x = list())) #> {xml_document} #> # Nesting multiple nodes as_xml_document(list(foo = list(bar = list(baz = list())))) #> {xml_document} #> #> [1] \\n \\n<\/bar> # attributes are stored as R attributes as_xml_document(list(foo = structure(list(), id = \"a\"))) #> {xml_document} #> as_xml_document(list(foo = list( bar = structure(list(), id = \"a\"), bar = structure(list(), id = \"b\") ))) #> {xml_document} #> #> [1] #> [2] "},{"path":"http://xml2.r-lib.org/dev/reference/download_xml.html","id":null,"dir":"Reference","previous_headings":"","what":"Download a HTML or XML file — download_xml","title":"Download a HTML or XML file — download_xml","text":"Libcurl implementation C_download (\"internal\" download method) added support https, ftps, gzip, etc. Default behavior identical download.file(), request can fully configured passing custom curl::handle().","code":""},{"path":"http://xml2.r-lib.org/dev/reference/download_xml.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Download a HTML or XML file — download_xml","text":"","code":"download_xml( url, file = basename(url), quiet = TRUE, mode = \"wb\", handle = curl::new_handle() ) download_html( url, file = basename(url), quiet = TRUE, mode = \"wb\", handle = curl::new_handle() )"},{"path":"http://xml2.r-lib.org/dev/reference/download_xml.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Download a HTML or XML file — download_xml","text":"url character string naming URL resource downloaded. file character string name downloaded file saved. quiet TRUE, suppress status messages (), progress bar. mode character string specifying mode write file. Useful values \"w\", \"wb\" (binary), \"\" (append) \"ab\". handle curl handle object","code":""},{"path":"http://xml2.r-lib.org/dev/reference/download_xml.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Download a HTML or XML file — download_xml","text":"Path downloaded file (invisibly).","code":""},{"path":"http://xml2.r-lib.org/dev/reference/download_xml.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Download a HTML or XML file — download_xml","text":"main difference curl_download curl_fetch_disk curl_download checks http status code starting download, raises error status non-successful. behavior curl_fetch_disk hand proceed normal write error page disk case non success response. advanced download interface supports concurrent requests resuming large files, look multi_download function.","code":""},{"path":[]},{"path":"http://xml2.r-lib.org/dev/reference/download_xml.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Download a HTML or XML file — download_xml","text":"","code":"if (FALSE) { download_html(\"http://tidyverse.org/index.html\") }"},{"path":"http://xml2.r-lib.org/dev/reference/oldclass.html","id":null,"dir":"Reference","previous_headings":"","what":"Register S4 classes — xml_document-class","title":"Register S4 classes — xml_document-class","text":"Classes exported can re-used within S4 classes, see methods::setOldClass(). xml_document: complete document. xml_nodeset: set nodes within document. xml_missing: missing object, e.g. empty result set. xml_node: single node document.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/read_xml.html","id":null,"dir":"Reference","previous_headings":"","what":"Read HTML or XML. — read_xml","title":"Read HTML or XML. — read_xml","text":"Read HTML XML.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/read_xml.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Read HTML or XML. — read_xml","text":"","code":"read_xml(x, encoding = \"\", ..., as_html = FALSE, options = \"NOBLANKS\") read_html(x, encoding = \"\", ..., options = c(\"RECOVER\", \"NOERROR\", \"NOBLANKS\")) # S3 method for character read_xml(x, encoding = \"\", ..., as_html = FALSE, options = \"NOBLANKS\") # S3 method for raw read_xml( x, encoding = \"\", base_url = \"\", ..., as_html = FALSE, options = \"NOBLANKS\" ) # S3 method for connection read_xml( x, encoding = \"\", n = 64 * 1024, verbose = FALSE, ..., base_url = \"\", as_html = FALSE, options = \"NOBLANKS\" )"},{"path":"http://xml2.r-lib.org/dev/reference/read_xml.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Read HTML or XML. — read_xml","text":"x string, connection, raw vector. string can either path, url literal xml. Urls converted connections either using base::url , installed, curl::curl. Local paths ending .gz, .bz2, .xz, .zip automatically uncompressed. connection, complete connection read raw vector parsed. encoding Specify default encoding document. Unless otherwise specified XML documents assumed UTF-8 UTF-16. document UTF-8/16, lacks explicit encoding directive, allows supply default. ... Additional arguments passed methods. as_html Optionally parse xml file html. options Set parsing options libxml2 parser. Zero RECOVER recover errors NOENT substitute entities DTDLOAD load external subset DTDATTR default DTD attributes DTDVALID validate DTD NOERROR suppress error reports NOWARNING suppress warning reports PEDANTIC pedantic error reporting NOBLANKS remove blank nodes SAX1 use SAX1 interface internally XINCLUDE Implement XInclude substitition NONET Forbid network access NODICT reuse context dictionary NSCLEAN remove redundant namespaces declarations NOCDATA merge CDATA text nodes NOXINCNODE generate XINCLUDE START/END nodes COMPACT compact small text nodes; modification tree allowed afterwards (possibly crash try modify tree) OLD10 parse using XML-1.0 update 5 NOBASEFIX fixup XINCLUDE xml:base uris HUGE relax hardcoded limit parser OLDSAX parse using SAX2 interface 2.7.0 IGNORE_ENC ignore internal document encoding hint BIG_LINES Store big lines numbers text PSVI field base_url loading connection, raw vector literal html/xml, allows specify base url document. Base urls used turn relative urls absolute urls. n file connection, number bytes read per iteration. Defaults 64kb. verbose reading slow connection, prints output every iteration know working.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/read_xml.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Read HTML or XML. — read_xml","text":"XML document. HTML normalised valid XML - may exactly transformation performed browser, reasonable approximation.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/read_xml.html","id":"setting-the-user-agent-header","dir":"Reference","previous_headings":"","what":"Setting the \"user agent\" header","title":"Read HTML or XML. — read_xml","text":"performing web scraping tasks good practice --- often required --- set user agent request header specific value. Sometimes value assigned emulate browser order content render certain way (e.g. Mozilla/5.0 (Windows NT 5.1; rv:52.0) Gecko/20100101 Firefox/52.0 emulate recent Windows browsers). often, value set provide web resource owner information intent actions like Google scraping bot user agent identifier: Googlebot/2.1 (+http://www.google.com/bot.html). can set HTTP user agent URL-based requests using httr::set_config() httr::user_agent(): httr::set_config(httr::user_agent(\"@example.com; +https://example.com/info.html\")) httr::set_config() changes configuration globally, httr::with_config() can used change configuration temporarily.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/read_xml.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Read HTML or XML. — read_xml","text":"","code":"# Literal xml/html is useful for small examples read_xml(\"<\/foo>\") #> {xml_document} #> #> [1] read_html(\"Hi<\/html>\") #> {html_document} #> #> [1] \\nHi\") #> {html_document} #> #> [1] \\n {html_document} #> #> [1] \\n [2] \\n \\n
\\n ... if (FALSE) { # From a url cd <- read_xml(xml2_example(\"cd_catalog.xml\")) me <- read_html(\"http://had.co.nz\") }"},{"path":"http://xml2.r-lib.org/dev/reference/url_absolute.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert between relative and absolute urls. — url_absolute","title":"Convert between relative and absolute urls. — url_absolute","text":"Convert relative absolute urls.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/url_absolute.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert between relative and absolute urls. — url_absolute","text":"","code":"url_absolute(x, base) url_relative(x, base)"},{"path":"http://xml2.r-lib.org/dev/reference/url_absolute.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert between relative and absolute urls. — url_absolute","text":"x character vector urls relative base base string giving base url.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/url_absolute.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Convert between relative and absolute urls. — url_absolute","text":"character vector urls","code":""},{"path":[]},{"path":"http://xml2.r-lib.org/dev/reference/url_absolute.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Convert between relative and absolute urls. — url_absolute","text":"","code":"url_absolute(c(\".\", \"..\", \"/\", \"/x\"), \"http://hadley.nz/a/b/c/d\") #> [1] \"http://hadley.nz/a/b/c/\" \"http://hadley.nz/a/b/\" #> [3] \"http://hadley.nz/\" \"http://hadley.nz/x\" url_relative(\"http://hadley.nz/a/c\", \"http://hadley.nz\") #> [1] \"/a/c\" url_relative(\"http://hadley.nz/a/c\", \"http://hadley.nz/\") #> [1] \"a/c\" url_relative(\"http://hadley.nz/a/c\", \"http://hadley.nz/a/b\") #> [1] \"c\" url_relative(\"http://hadley.nz/a/c\", \"http://hadley.nz/a/b/\") #> [1] \"../c\""},{"path":"http://xml2.r-lib.org/dev/reference/url_escape.html","id":null,"dir":"Reference","previous_headings":"","what":"Escape and unescape urls. — url_escape","title":"Escape and unescape urls. — url_escape","text":"Escape unescape urls.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/url_escape.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Escape and unescape urls. — url_escape","text":"","code":"url_escape(x, reserved = \"\") url_unescape(x)"},{"path":"http://xml2.r-lib.org/dev/reference/url_escape.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Escape and unescape urls. — url_escape","text":"x character vector urls. reserved string containing additional characters avoid escaping.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/url_escape.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Escape and unescape urls. — url_escape","text":"","code":"url_escape(\"a b c\") #> [1] \"a%20b%20c\" url_escape(\"a b c\", \"\") #> [1] \"a%20b%20c\" url_unescape(\"a%20b%2fc\") #> [1] \"a b/c\" url_unescape(\"%C2%B5\") #> [1] \"µ\""},{"path":"http://xml2.r-lib.org/dev/reference/url_parse.html","id":null,"dir":"Reference","previous_headings":"","what":"Parse a url into its component pieces. — url_parse","title":"Parse a url into its component pieces. — url_parse","text":"Parse url component pieces.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/url_parse.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Parse a url into its component pieces. — url_parse","text":"","code":"url_parse(x)"},{"path":"http://xml2.r-lib.org/dev/reference/url_parse.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Parse a url into its component pieces. — url_parse","text":"x character vector urls.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/url_parse.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Parse a url into its component pieces. — url_parse","text":"dataframe one row element x columns: scheme, server, port, user, path, query, fragment.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/url_parse.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Parse a url into its component pieces. — url_parse","text":"","code":"url_parse(\"http://had.co.nz/\") #> scheme server port user path query fragment #> 1 http had.co.nz NA / url_parse(\"http://had.co.nz:1234/\") #> scheme server port user path query fragment #> 1 http had.co.nz 1234 / url_parse(\"http://had.co.nz:1234/?a=1&b=2\") #> scheme server port user path query fragment #> 1 http had.co.nz 1234 / a=1&b=2 url_parse(\"http://had.co.nz:1234/?a=1&b=2#def\") #> scheme server port user path query fragment #> 1 http had.co.nz 1234 / a=1&b=2 def"},{"path":"http://xml2.r-lib.org/dev/reference/write_xml.html","id":null,"dir":"Reference","previous_headings":"","what":"Write XML or HTML to disk. — write_xml","title":"Write XML or HTML to disk. — write_xml","text":"writes XML normalised HTML. default behavior output format read. want force output pass option = \"as_xml\" option = \"as_html\" respectively.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/write_xml.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Write XML or HTML to disk. — write_xml","text":"","code":"write_xml(x, file, ...) # S3 method for xml_document write_xml(x, file, ..., options = \"format\", encoding = \"UTF-8\") write_html(x, file, ...) # S3 method for xml_document write_html(x, file, ..., options = \"format\", encoding = \"UTF-8\")"},{"path":"http://xml2.r-lib.org/dev/reference/write_xml.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Write XML or HTML to disk. — write_xml","text":"x document node write disk. possible save nodesets containing one node. file Path file connection write . ... additional arguments passed methods. options default: ‘format’. Zero format Format output no_declaration Drop XML declaration no_empty_tags Remove empty tags no_xhtml Disable XHTML1 rules require_xhtml Force XHTML rules as_xml Force XML output as_html Force HTML output format_whitespace Format non-significant whitespace encoding character encoding use document. default encoding ‘UTF-8’. Available encodings specified http://xmlsoft.org/html/libxml-encoding.html#xmlCharEncoding.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/write_xml.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Write XML or HTML to disk. — write_xml","text":"","code":"h <- read_html(\"
Hi!<\/p>\") tmp <- tempfile(fileext = \".xml\") write_xml(h, tmp, options = \"format\") readLines(tmp) #> [1] \"\" #> [2] \"
Hi!<\/p><\/body><\/html>\" # write formatted HTML output write_html(h, tmp, options = \"format\") readLines(tmp) #> [1] \"\" #> [2] \"
Hi!<\/p><\/body><\/html>\""},{"path":"http://xml2.r-lib.org/dev/reference/xml2-package.html","id":null,"dir":"Reference","previous_headings":"","what":"xml2: Parse XML — xml2-package","title":"xml2: Parse XML — xml2-package","text":"Work XML files using simple, consistent interface. Built top 'libxml2' C library.","code":""},{"path":[]},{"path":"http://xml2.r-lib.org/dev/reference/xml2-package.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"xml2: Parse XML — xml2-package","text":"Maintainer: Hadley Wickham hadley@posit.co Authors: Jim Hester Jeroen Ooms contributors: Posit Software, PBC [copyright holder, funder] R Foundation (Copy R-project homepage cached example) [contributor]","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml2_example.html","id":null,"dir":"Reference","previous_headings":"","what":"Get path to a xml2 example — xml2_example","title":"Get path to a xml2 example — xml2_example","text":"xml2 comes bundled number sample files ‘inst/extdata’ directory. function makes easy access.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml2_example.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get path to a xml2 example — xml2_example","text":"","code":"xml2_example(path = NULL)"},{"path":"http://xml2.r-lib.org/dev/reference/xml2_example.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get path to a xml2 example — xml2_example","text":"path Name file. NULL, example files listed.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_attr.html","id":null,"dir":"Reference","previous_headings":"","what":"Retrieve an attribute. — xml_attr","title":"Retrieve an attribute. — xml_attr","text":"xml_attrs() retrieves attributes values named character vector, xml_attrs() <- xml_set_attrs() sets attribute values. xml_attr() retrieves value single attribute xml_attr() <- xml_set_attr() modifies value. attribute exist, return default, defaults NA. xml_has_attr() tests attribute present.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_attr.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Retrieve an attribute. — xml_attr","text":"","code":"xml_attr(x, attr, ns = character(), default = NA_character_) xml_has_attr(x, attr, ns = character()) xml_attrs(x, ns = character()) xml_attr(x, attr, ns = character()) <- value xml_set_attr(x, attr, value, ns = character()) xml_attrs(x, ns = character()) <- value xml_set_attrs(x, value, ns = character())"},{"path":"http://xml2.r-lib.org/dev/reference/xml_attr.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Retrieve an attribute. — xml_attr","text":"x document, node, node set. attr Name attribute extract. ns Optionally, named vector giving prefix-url pairs, produced xml_ns(). provided, names explicitly qualified ns prefix, .e. element bar defined namespace foo, called foo:bar. (similarly attributes). Default namespaces must given explicit name. ns ignored using xml_name<-() xml_set_name(). default Default value use attribute present. value character vector new value.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_attr.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Retrieve an attribute. — xml_attr","text":"xml_attr() returns character vector. NA used represent attributes defined. xml_has_attr() returns logical vector. xml_attrs() returns named character vector x x single node, list character vectors given nodeset","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_attr.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Retrieve an attribute. — xml_attr","text":"","code":"x <- read_xml(\"<\/root>\") xml_attr(x, \"id\") #> [1] \"1\" xml_attr(x, \"apple\") #> [1] NA xml_attrs(x) #> id #> \"1\" kids <- xml_children(x) kids #> {xml_nodeset (2)} #> [1] #> [2] xml_attr(kids, \"id\") #> [1] \"a\" \"b\" xml_has_attr(kids, \"id\") #> [1] TRUE TRUE xml_attrs(kids) #> [[1]] #> id #> \"a\" #> #> [[2]] #> id d #> \"b\" \"b\" #> # Missing attributes give missing values xml_attr(xml_children(x), \"d\") #> [1] NA \"b\" xml_has_attr(xml_children(x), \"d\") #> [1] FALSE TRUE # If the document has a namespace, use the ns argument and # qualified attribute names x <- read_xml(' <\/root> ') doc <- xml_children(x)[[1]] ns <- xml_ns(x) xml_attrs(doc) #> id id id #> \"b\" \"f\" \"b\" xml_attrs(doc, ns) #> b:id f:id id #> \"b\" \"f\" \"\" # If you don't supply a ns spec, you get the first matching attribute xml_attr(doc, \"id\") #> [1] \"b\" xml_attr(doc, \"b:id\", ns) #> [1] \"b\" xml_attr(doc, \"id\", ns) #> [1] \"\" # Can set a single attribute with `xml_attr() <-` or `xml_set_attr()` xml_attr(doc, \"id\") <- \"one\" xml_set_attr(doc, \"id\", \"two\") # Or set multiple attributes with `xml_attrs()` or `xml_set_attrs()` xml_attrs(doc) <- c(\"b:id\" = \"one\", \"f:id\" = \"two\", \"id\" = \"three\") xml_set_attrs(doc, c(\"b:id\" = \"one\", \"f:id\" = \"two\", \"id\" = \"three\"))"},{"path":"http://xml2.r-lib.org/dev/reference/xml_cdata.html","id":null,"dir":"Reference","previous_headings":"","what":"Construct a cdata node — xml_cdata","title":"Construct a cdata node — xml_cdata","text":"Construct cdata node","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_cdata.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Construct a cdata node — xml_cdata","text":"","code":"xml_cdata(content)"},{"path":"http://xml2.r-lib.org/dev/reference/xml_cdata.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Construct a cdata node — xml_cdata","text":"content CDATA content, include \")) as.character(x) #> [1] \"\\n]]><\/root>\\n\""},{"path":"http://xml2.r-lib.org/dev/reference/xml_children.html","id":null,"dir":"Reference","previous_headings":"","what":"Navigate around the family tree. — xml_children","title":"Navigate around the family tree. — xml_children","text":"xml_children returns elements, xml_contents returns nodes. xml_length returns number children. xml_parent returns parent node, xml_parents returns parents root. xml_siblings returns nodes level. xml_child makes easy specify specific child return.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_children.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Navigate around the family tree. — xml_children","text":"","code":"xml_children(x) xml_child(x, search = 1, ns = xml_ns(x)) xml_contents(x) xml_parents(x) xml_siblings(x) xml_parent(x) xml_length(x, only_elements = TRUE) xml_root(x)"},{"path":"http://xml2.r-lib.org/dev/reference/xml_children.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Navigate around the family tree. — xml_children","text":"x document, node, node set. search xml_child, either child number return (position), name child node return. multiple child nodes name, first returned ns Optionally, named vector giving prefix-url pairs, produced xml_ns(). provided, names explicitly qualified ns prefix, .e. element bar defined namespace foo, called foo:bar. (similarly attributes). Default namespaces must given explicit name. ns ignored using xml_name<-() xml_set_name(). only_elements xml_length, count children, just children elements (default)?","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_children.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Navigate around the family tree. — xml_children","text":"node nodeset (possibly empty). Results always de-duplicated.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_children.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Navigate around the family tree. — xml_children","text":"","code":"x <- read_xml(\" <\/bar> <\/foo>\") xml_children(x) #> {xml_nodeset (2)} #> [1] \\n \\n<\/bar> #> [2] xml_children(xml_children(x)) #> {xml_nodeset (1)} #> [1] xml_siblings(xml_children(x)[[1]]) #> {xml_nodeset (1)} #> [1] # Note the each unique node only appears once in the output xml_parent(xml_children(x)) #> {xml_nodeset (1)} #> [1] \\n \\n \\n <\/bar>\\n \\n<\/foo> # Mixed content x <- read_xml(\" a c e<\/d> f<\/foo>\") # Childen gets the elements, contents gets all node types xml_children(x) #> {xml_nodeset (2)} #> [1] #> [2] e<\/d> xml_contents(x) #> {xml_nodeset (5)} #> [1] a #> [2] #> [3] c #> [4] e<\/d> #> [5] f xml_length(x) #> [1] 2 xml_length(x, only_elements = FALSE) #> [1] 5 # xml_child makes it easier to select specific children xml_child(x) #> {xml_node} #> xml_child(x, 2) #> {xml_node} #> xml_child(x, \"baz\") #> {xml_missing} #> "},{"path":"http://xml2.r-lib.org/dev/reference/xml_comment.html","id":null,"dir":"Reference","previous_headings":"","what":"Construct a comment node — xml_comment","title":"Construct a comment node — xml_comment","text":"Construct comment node","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_comment.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Construct a comment node — xml_comment","text":"","code":"xml_comment(content)"},{"path":"http://xml2.r-lib.org/dev/reference/xml_comment.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Construct a comment node — xml_comment","text":"content comment content","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_comment.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Construct a comment node — xml_comment","text":"","code":"x <- xml_new_document() r <- xml_add_child(x, \"root\") xml_add_child(r, xml_comment(\"Hello!\")) as.character(x) #> [1] \"\\n\\n \\n<\/root>\\n\""},{"path":"http://xml2.r-lib.org/dev/reference/xml_dtd.html","id":null,"dir":"Reference","previous_headings":"","what":"Construct a document type definition — xml_dtd","title":"Construct a document type definition — xml_dtd","text":"used create simple document type definitions. need create complicated definition internal subsets recommended parse string directly read_xml().","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_dtd.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Construct a document type definition — xml_dtd","text":"","code":"xml_dtd(name = \"\", external_id = \"\", system_id = \"\")"},{"path":"http://xml2.r-lib.org/dev/reference/xml_dtd.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Construct a document type definition — xml_dtd","text":"name name declaration external_id external ID declaration system_id system ID declaration","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_dtd.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Construct a document type definition — xml_dtd","text":"","code":"r <- xml_new_root( xml_dtd( \"html\", \"-//W3C//DTD XHTML 1.0 Transitional//EN\", \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\" ) ) # Use read_xml directly for more complicated DTD d <- read_xml( ' ]> This is a valid document &foo; !<\/doc>' )"},{"path":"http://xml2.r-lib.org/dev/reference/xml_find_all.html","id":null,"dir":"Reference","previous_headings":"","what":"Find nodes that match an xpath expression. — xml_find_all","title":"Find nodes that match an xpath expression. — xml_find_all","text":"Xpath like regular expressions trees - worth learning trying extract nodes arbitrary locations document. Use xml_find_all find matches - match get empty result. Use xml_find_first find specific match - match get xml_missing node.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_find_all.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Find nodes that match an xpath expression. — xml_find_all","text":"","code":"xml_find_all(x, xpath, ns = xml_ns(x), ...) # S3 method for xml_nodeset xml_find_all(x, xpath, ns = xml_ns(x), flatten = TRUE, ...) xml_find_first(x, xpath, ns = xml_ns(x)) xml_find_num(x, xpath, ns = xml_ns(x)) xml_find_int(x, xpath, ns = xml_ns(x)) xml_find_chr(x, xpath, ns = xml_ns(x)) xml_find_lgl(x, xpath, ns = xml_ns(x))"},{"path":"http://xml2.r-lib.org/dev/reference/xml_find_all.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Find nodes that match an xpath expression. — xml_find_all","text":"x document, node, node set. xpath string containing xpath (1.0) expression. ns Optionally, named vector giving prefix-url pairs, produced xml_ns(). provided, names explicitly qualified ns prefix, .e. element bar defined namespace foo, called foo:bar. (similarly attributes). Default namespaces must given explicit name. ns ignored using xml_name<-() xml_set_name(). ... arguments passed methods. flatten logical indicating whether return single, flattened nodeset list nodesets.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_find_all.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Find nodes that match an xpath expression. — xml_find_all","text":"xml_find_all returns nodeset applied node, nodeset list nodesets applied nodeset. matches, nodeset(s) empty. Within nodeset, result always unique; repeated nodes automatically de-duplicated. xml_find_first returns node applied node, nodeset applied nodeset. output always size input. matches, xml_find_first return missing node; multiple matches, return first . xml_find_num, xml_find_chr, xml_find_lgl return numeric, character logical results respectively.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_find_all.html","id":"deprecated-functions","dir":"Reference","previous_headings":"","what":"Deprecated functions","title":"Find nodes that match an xpath expression. — xml_find_all","text":"xml_find_one() deprecated. Instead use xml_find_first().","code":""},{"path":[]},{"path":"http://xml2.r-lib.org/dev/reference/xml_find_all.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Find nodes that match an xpath expression. — xml_find_all","text":"","code":"x <- read_xml(\"<\/bar><\/foo>\") xml_find_all(x, \".//baz\") #> {xml_nodeset (2)} #> [1] #> [2] xml_path(xml_find_all(x, \".//baz\")) #> [1] \"/foo/bar/baz\" \"/foo/baz\" # Note the difference between .// and // # // finds anywhere in the document (ignoring the current node) # .// finds anywhere beneath the current node (bar <- xml_find_all(x, \".//bar\")) #> {xml_nodeset (1)} #> [1] \\n \\n<\/bar> xml_find_all(bar, \".//baz\") #> {xml_nodeset (1)} #> [1] xml_find_all(bar, \"//baz\") #> {xml_nodeset (2)} #> [1] #> [2] # Find all vs find one ----------------------------------------------------- x <- read_xml(\" Some text<\/b>.<\/p>
Some other<\/b> text<\/b>.<\/p>
No bold here!<\/p> <\/body>\") para <- xml_find_all(x, \".//p\") # By default, if you apply xml_find_all to a nodeset, it finds all matches, # de-duplicates them, and returns as a single nodeset. This means you # never know how many results you'll get xml_find_all(para, \".//b\") #> {xml_nodeset (3)} #> [1] text<\/b> #> [2] other<\/b> #> [3] text<\/b> # If you set flatten to FALSE, though, xml_find_all will return a list of # nodesets, where each nodeset contains the matches for the corresponding # node in the original nodeset. xml_find_all(para, \".//b\", flatten = FALSE) #> [[1]] #> {xml_nodeset (1)} #> [1] text<\/b> #> #> [[2]] #> {xml_nodeset (2)} #> [1] other<\/b> #> [2] text<\/b> #> #> [[3]] #> {xml_nodeset (0)} #> # xml_find_first only returns the first match per input node. If there are 0 # matches it will return a missing node xml_find_first(para, \".//b\") #> {xml_nodeset (3)} #> [1] text<\/b> #> [2] other<\/b> #> [3] NA xml_text(xml_find_first(para, \".//b\")) #> [1] \"text\" \"other\" NA # Namespaces --------------------------------------------------------------- # If the document uses namespaces, you'll need use xml_ns to form # a unique mapping between full namespace url and a short prefix x <- read_xml(' <\/f:doc> <\/f:doc> <\/root> ') xml_find_all(x, \".//f:doc\") #> {xml_nodeset (2)} #> [1] \\n \\n<\/f:doc> #> [2] \\n \\n<\/f:doc> xml_find_all(x, \".//f:doc\", xml_ns(x)) #> {xml_nodeset (2)} #> [1] \\n \\n<\/f:doc> #> [2] \\n \\n<\/f:doc>"},{"path":"http://xml2.r-lib.org/dev/reference/xml_missing.html","id":null,"dir":"Reference","previous_headings":"","what":"Construct an missing xml object — xml_missing","title":"Construct an missing xml object — xml_missing","text":"Construct missing xml object","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_missing.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Construct an missing xml object — xml_missing","text":"","code":"xml_missing()"},{"path":"http://xml2.r-lib.org/dev/reference/xml_name.html","id":null,"dir":"Reference","previous_headings":"","what":"The (tag) name of an xml element. — xml_name","title":"The (tag) name of an xml element. — xml_name","text":"(tag) name xml element. Modify (tag) name element","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_name.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"The (tag) name of an xml element. — xml_name","text":"","code":"xml_name(x, ns = character()) xml_name(x, ns = character()) <- value xml_set_name(x, value, ns = character())"},{"path":"http://xml2.r-lib.org/dev/reference/xml_name.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"The (tag) name of an xml element. — xml_name","text":"x document, node, node set. ns Optionally, named vector giving prefix-url pairs, produced xml_ns(). provided, names explicitly qualified ns prefix, .e. element bar defined namespace foo, called foo:bar. (similarly attributes). Default namespaces must given explicit name. ns ignored using xml_name<-() xml_set_name(). value character vector replacement name.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_name.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"The (tag) name of an xml element. — xml_name","text":"character vector.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_name.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"The (tag) name of an xml element. — xml_name","text":"","code":"x <- read_xml(\"123<\/bar>\") xml_name(x) #> [1] \"bar\" y <- read_xml(\"1<\/baz>abc<\/bar>\") z <- xml_children(y) xml_name(xml_children(y)) #> [1] \"baz\" \"foo\""},{"path":"http://xml2.r-lib.org/dev/reference/xml_new_document.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a new document, possibly with a root node — xml_new_document","title":"Create a new document, possibly with a root node — xml_new_document","text":"xml_new_document creates new document without root node. cases instead use xml_new_root, creates new document assigns root node one step.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_new_document.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a new document, possibly with a root node — xml_new_document","text":"","code":"xml_new_document(version = \"1.0\", encoding = \"UTF-8\") xml_new_root( .value, ..., .copy = inherits(.value, \"xml_node\"), .version = \"1.0\", .encoding = \"UTF-8\" )"},{"path":"http://xml2.r-lib.org/dev/reference/xml_new_document.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a new document, possibly with a root node — xml_new_document","text":"version version number document. encoding character encoding use document. default encoding ‘UTF-8’. Available encodings specified http://xmlsoft.org/html/libxml-encoding.html#xmlCharEncoding. .value node insert. ... named attributes namespaces set node, unnamed text assign node. .copy whether copy .value replacing. FALSE node moved current location. .version version number document, passed xml_new_document(version). .encoding encoding document, passed xml_new_document(encoding).","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_new_document.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a new document, possibly with a root node — xml_new_document","text":"xml_document object.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_ns.html","id":null,"dir":"Reference","previous_headings":"","what":"XML namespaces. — xml_ns","title":"XML namespaces. — xml_ns","text":"xml_ns extracts namespaces document, matching unique namespace url prefix first associated . Default namespaces named d1, d2 etc. Use xml_ns_rename change prefixes. namespace object, can pass functions work fully qualified names instead local names.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_ns.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"XML namespaces. — xml_ns","text":"","code":"xml_ns(x) xml_ns_rename(old, ...)"},{"path":"http://xml2.r-lib.org/dev/reference/xml_ns.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"XML namespaces. — xml_ns","text":"x document, node, node set. old, ... existing xml_namespace object followed name-value (old prefix-new prefix) pairs replace.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_ns.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"XML namespaces. — xml_ns","text":"character vector class xml_namespace default display little nicer.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_ns.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"XML namespaces. — xml_ns","text":"","code":"x <- read_xml(' <\/doc1> <\/doc2> <\/root> ') xml_ns(x) #> d1 <-> http://foo.com #> d2 <-> http://bar.com # When there are default namespaces, it's a good idea to rename # them to give informative names: ns <- xml_ns_rename(xml_ns(x), d1 = \"foo\", d2 = \"bar\") ns #> foo <-> http://foo.com #> bar <-> http://bar.com # Now we can pass ns to other xml function to use fully qualified names baz <- xml_children(xml_children(x)) xml_name(baz) #> [1] \"baz\" \"baz\" xml_name(baz, ns) #> [1] \"foo:baz\" \"bar:baz\" xml_find_all(x, \"//baz\") #> {xml_nodeset (0)} xml_find_all(x, \"//foo:baz\", ns) #> {xml_nodeset (1)} #> [1] str(as_list(x)) #> List of 1 #> $ root:List of 2 #> ..$ doc1:List of 1 #> .. ..$ baz: list() #> .. ..- attr(*, \"xmlns\")= chr \"http://foo.com\" #> ..$ doc2:List of 1 #> .. ..$ baz: list() #> .. ..- attr(*, \"xmlns\")= chr \"http://bar.com\" str(as_list(x, ns)) #> List of 1 #> $ root:List of 2 #> ..$ foo:doc1:List of 1 #> .. ..$ foo:baz: list() #> .. ..- attr(*, \"xmlns\")= chr \"http://foo.com\" #> ..$ bar:doc2:List of 1 #> .. ..$ bar:baz: list() #> .. ..- attr(*, \"xmlns\")= chr \"http://bar.com\""},{"path":"http://xml2.r-lib.org/dev/reference/xml_ns_strip.html","id":null,"dir":"Reference","previous_headings":"","what":"Strip the default namespaces from a document — xml_ns_strip","title":"Strip the default namespaces from a document — xml_ns_strip","text":"Strip default namespaces document","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_ns_strip.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Strip the default namespaces from a document — xml_ns_strip","text":"","code":"xml_ns_strip(x)"},{"path":"http://xml2.r-lib.org/dev/reference/xml_ns_strip.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Strip the default namespaces from a document — xml_ns_strip","text":"x document, node, node set.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_ns_strip.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Strip the default namespaces from a document — xml_ns_strip","text":"","code":"x <- read_xml( \" <\/bar> <\/foo>\" ) # Need to specify the default namespaces to find the baz nodes xml_find_all(x, \"//d1:baz\") #> {xml_nodeset (1)} #> [1] xml_find_all(x, \"//d2:baz\") #> {xml_nodeset (1)} #> [1] # After stripping the default namespaces you can find both baz nodes directly xml_ns_strip(x) xml_find_all(x, \"//baz\") #> {xml_nodeset (2)} #> [1] #> [2] "},{"path":"http://xml2.r-lib.org/dev/reference/xml_path.html","id":null,"dir":"Reference","previous_headings":"","what":"Retrieve the xpath to a node — xml_path","title":"Retrieve the xpath to a node — xml_path","text":"useful want figure nodes matching xpath expression live document.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_path.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Retrieve the xpath to a node — xml_path","text":"","code":"xml_path(x)"},{"path":"http://xml2.r-lib.org/dev/reference/xml_path.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Retrieve the xpath to a node — xml_path","text":"x document, node, node set.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_path.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Retrieve the xpath to a node — xml_path","text":"character vector.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_path.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Retrieve the xpath to a node — xml_path","text":"","code":"x <- read_xml(\"<\/bar><\/foo>\") xml_path(xml_find_all(x, \".//baz\")) #> [1] \"/foo/bar/baz\" \"/foo/baz\""},{"path":"http://xml2.r-lib.org/dev/reference/xml_replace.html","id":null,"dir":"Reference","previous_headings":"","what":"Modify a tree by inserting, replacing or removing nodes — xml_replace","title":"Modify a tree by inserting, replacing or removing nodes — xml_replace","text":"xml_add_sibling() xml_add_child() used insert node sibling child. xml_add_parent() adds new parent input node current parent. xml_replace() replaces existing node new node. xml_remove() removes node tree.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_replace.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Modify a tree by inserting, replacing or removing nodes — xml_replace","text":"","code":"xml_replace(.x, .value, ..., .copy = TRUE) xml_add_sibling(.x, .value, ..., .where = c(\"after\", \"before\"), .copy = TRUE) xml_add_child(.x, .value, ..., .where = length(xml_children(.x)), .copy = TRUE) xml_add_parent(.x, .value, ...) xml_remove(.x, free = FALSE)"},{"path":"http://xml2.r-lib.org/dev/reference/xml_replace.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Modify a tree by inserting, replacing or removing nodes — xml_replace","text":".x document, node nodeset. .value node insert. ... named attributes namespaces set node, unnamed text assign node. .copy whether copy .value replacing. FALSE node moved current location. .add new node, xml_add_child position add, use 0 first child. xml_add_sibling either ‘\"\"’ ‘\"\"’ indicating new node .x. free removing node also free memory used node. Note use option use existing objects pointing node children, likely crash R return garbage.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_replace.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Modify a tree by inserting, replacing or removing nodes — xml_replace","text":"Care needs taken using xml_remove(),","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_serialize.html","id":null,"dir":"Reference","previous_headings":"","what":"Serializing XML objects to connections. — xml_serialize","title":"Serializing XML objects to connections. — xml_serialize","text":"Serializing XML objects connections.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_serialize.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Serializing XML objects to connections. — xml_serialize","text":"","code":"xml_serialize(object, connection, ...) xml_unserialize(connection, ...)"},{"path":"http://xml2.r-lib.org/dev/reference/xml_serialize.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Serializing XML objects to connections. — xml_serialize","text":"object R object serialize. connection open connection (serialize) NULL (unserialize) raw vector (see ‘Details’). ... Additional arguments passed read_xml().","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_serialize.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Serializing XML objects to connections. — xml_serialize","text":"serialize, NULL unless connection = NULL, result returned raw vector. unserialize R object.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_serialize.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Serializing XML objects to connections. — xml_serialize","text":"","code":"library(xml2) x <- read_xml(\" 123<\/c><\/b> 456<\/c><\/b> <\/a>\") b <- xml_find_all(x, \"//b\") out <- xml_serialize(b, NULL) xml_unserialize(out) #> {xml_nodeset (2)} #> [1] \\n 123<\/c>\\n<\/b> #> [2] \\n 456<\/c>\\n<\/b>"},{"path":"http://xml2.r-lib.org/dev/reference/xml_set_namespace.html","id":null,"dir":"Reference","previous_headings":"","what":"Set the node's namespace — xml_set_namespace","title":"Set the node's namespace — xml_set_namespace","text":"namespace set must already defined one node's ancestors.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_set_namespace.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Set the node's namespace — xml_set_namespace","text":"","code":"xml_set_namespace(.x, prefix = \"\", uri = \"\")"},{"path":"http://xml2.r-lib.org/dev/reference/xml_set_namespace.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Set the node's namespace — xml_set_namespace","text":".x node prefix namespace prefix use uri namespace URI use","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_set_namespace.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Set the node's namespace — xml_set_namespace","text":"node (invisibly)","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_structure.html","id":null,"dir":"Reference","previous_headings":"","what":"Show the structure of an html/xml document. — xml_structure","title":"Show the structure of an html/xml document. — xml_structure","text":"Show structure html/xml document without displaying values. useful want get high level view way document organised. Compared xml_structure, html_structure prints id class attributes.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_structure.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Show the structure of an html/xml document. — xml_structure","text":"","code":"xml_structure(x, indent = 2, file = \"\") html_structure(x, indent = 2, file = \"\")"},{"path":"http://xml2.r-lib.org/dev/reference/xml_structure.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Show the structure of an html/xml document. — xml_structure","text":"x HTML/XML document (part ) indent Number spaces ident file connection, character string naming file print . \"\" (default), cat prints standard output connection, console unless redirected sink. \"|cmd\", output piped command given cmd, opening pipe connection.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_structure.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Show the structure of an html/xml document. — xml_structure","text":"","code":"xml_structure(read_xml(\"<\/b><\/a>\")) #> #> #> #> #> rproj <- read_html(system.file(\"extdata\", \"r-project.html\", package = \"xml2\")) xml_structure(rproj) #> #> #> #> #> #> #> {text} #> #> #> {comment} #> #> #> {comment} #> {comment} #> {comment} #> #> {text} #>