From 18371068946b5746195d2d21a91eec699eeb1c35 Mon Sep 17 00:00:00 2001 From: jeroen Date: Tue, 9 Jan 2024 23:32:21 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20r-lib/xm?= =?UTF-8?q?l2@ab73051bca962d3cbcf8f4046eb2758be74a489c=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dev/articles/modification.html | 8 ++++---- dev/pkgdown.yml | 2 +- dev/search.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dev/articles/modification.html b/dev/articles/modification.html index 1852eda9..9d9d334f 100644 --- a/dev/articles/modification.html +++ b/dev/articles/modification.html @@ -285,8 +285,8 @@

Removing nodesrm(x1) gc() #> used (Mb) gc trigger (Mb) max used (Mb) -#> Ncells 672184 35.9 1326505 70.9 1326505 70.9 -#> Vcells 1167942 9.0 8388608 64.0 2566051 19.6 +#> Ncells 672183 35.9 1326505 70.9 1326505 70.9 +#> Vcells 1167940 9.0 8388608 64.0 2566043 19.6 x2 #> {xml_node} @@ -309,8 +309,8 @@

Removing nodesrm(bees) gc() #> used (Mb) gc trigger (Mb) max used (Mb) -#> Ncells 672191 35.9 1326505 70.9 1326505 70.9 -#> Vcells 1167944 9.0 8388608 64.0 2566051 19.6 +#> Ncells 672190 35.9 1326505 70.9 1326505 70.9 +#> Vcells 1167938 9.0 8388608 64.0 2566043 19.6

Namespaces diff --git a/dev/pkgdown.yml b/dev/pkgdown.yml index 79e9ad74..ae80be3e 100644 --- a/dev/pkgdown.yml +++ b/dev/pkgdown.yml @@ -3,7 +3,7 @@ pkgdown: 2.0.7 pkgdown_sha: ~ articles: modification: modification.html -last_built: 2024-01-09T23:15Z +last_built: 2024-01-09T23:32Z urls: reference: http://xml2.r-lib.org/reference article: http://xml2.r-lib.org/articles diff --git a/dev/search.json b/dev/search.json index 0c041ad1..9b692342 100644 --- a/dev/search.json +++ b/dev/search.json @@ -1 +1 @@ -[{"path":[]},{"path":"http://xml2.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"our-pledge","dir":"","previous_headings":"","what":"Our Pledge","title":"Contributor Covenant Code of Conduct","text":"members, contributors, leaders pledge make participation community harassment-free experience everyone, regardless age, body size, visible invisible disability, ethnicity, sex characteristics, gender identity expression, level experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, sexual identity orientation. pledge act interact ways contribute open, welcoming, diverse, inclusive, healthy community.","code":""},{"path":"http://xml2.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"our-standards","dir":"","previous_headings":"","what":"Our Standards","title":"Contributor Covenant Code of Conduct","text":"Examples behavior contributes positive environment community include: Demonstrating empathy kindness toward people respectful differing opinions, viewpoints, experiences Giving gracefully accepting constructive feedback Accepting responsibility apologizing affected mistakes, learning experience Focusing best just us individuals, overall community Examples unacceptable behavior include: use sexualized language imagery, sexual attention advances kind Trolling, insulting derogatory comments, personal political attacks Public private harassment Publishing others’ private information, physical email address, without explicit permission conduct reasonably considered inappropriate professional setting","code":""},{"path":"http://xml2.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement-responsibilities","dir":"","previous_headings":"","what":"Enforcement Responsibilities","title":"Contributor Covenant Code of Conduct","text":"Community leaders responsible clarifying enforcing standards acceptable behavior take appropriate fair corrective action response behavior deem inappropriate, threatening, offensive, harmful. Community leaders right responsibility remove, edit, reject comments, commits, code, wiki edits, issues, contributions aligned Code Conduct, communicate reasons moderation decisions appropriate.","code":""},{"path":"http://xml2.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"scope","dir":"","previous_headings":"","what":"Scope","title":"Contributor Covenant Code of Conduct","text":"Code Conduct applies within community spaces, also applies individual officially representing community public spaces. Examples representing community include using official e-mail address, posting via official social media account, acting appointed representative online offline event.","code":""},{"path":"http://xml2.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement","dir":"","previous_headings":"","what":"Enforcement","title":"Contributor Covenant Code of Conduct","text":"Instances abusive, harassing, otherwise unacceptable behavior may reported community leaders responsible enforcement codeofconduct@posit.co. complaints reviewed investigated promptly fairly. community leaders obligated respect privacy security reporter incident.","code":""},{"path":"http://xml2.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement-guidelines","dir":"","previous_headings":"","what":"Enforcement Guidelines","title":"Contributor Covenant Code of Conduct","text":"Community leaders follow Community Impact Guidelines determining consequences action deem violation Code Conduct:","code":""},{"path":"http://xml2.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_1-correction","dir":"","previous_headings":"Enforcement Guidelines","what":"1. Correction","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Use inappropriate language behavior deemed unprofessional unwelcome community. Consequence: private, written warning community leaders, providing clarity around nature violation explanation behavior inappropriate. public apology may requested.","code":""},{"path":"http://xml2.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_2-warning","dir":"","previous_headings":"Enforcement Guidelines","what":"2. Warning","title":"Contributor Covenant Code of Conduct","text":"Community Impact: violation single incident series actions. Consequence: warning consequences continued behavior. interaction people involved, including unsolicited interaction enforcing Code Conduct, specified period time. includes avoiding interactions community spaces well external channels like social media. Violating terms may lead temporary permanent ban.","code":""},{"path":"http://xml2.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_3-temporary-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"3. Temporary Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: serious violation community standards, including sustained inappropriate behavior. Consequence: temporary ban sort interaction public communication community specified period time. public private interaction people involved, including unsolicited interaction enforcing Code Conduct, allowed period. Violating terms may lead permanent ban.","code":""},{"path":"http://xml2.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_4-permanent-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"4. Permanent Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Demonstrating pattern violation community standards, including sustained inappropriate behavior, harassment individual, aggression toward disparagement classes individuals. Consequence: permanent ban sort public interaction within community.","code":""},{"path":"http://xml2.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"attribution","dir":"","previous_headings":"","what":"Attribution","title":"Contributor Covenant Code of Conduct","text":"Code Conduct adapted Contributor Covenant, version 2.1, available https://www.contributor-covenant.org/version/2/1/code_of_conduct.html. Community Impact Guidelines inspired [Mozilla’s code conduct enforcement ladder][https://github.com/mozilla/inclusion]. answers common questions code conduct, see FAQ https://www.contributor-covenant.org/faq. Translations available https://www.contributor-covenant.org/translations.","code":""},{"path":"http://xml2.r-lib.org/dev/CONTRIBUTING.html","id":null,"dir":"","previous_headings":"","what":"Contributing to xml2","title":"Contributing to xml2","text":"outlines propose change xml2. detailed info contributing , tidyverse packages, please see development contributing guide.","code":""},{"path":"http://xml2.r-lib.org/dev/CONTRIBUTING.html","id":"fixing-typos","dir":"","previous_headings":"","what":"Fixing typos","title":"Contributing to xml2","text":"can fix typos, spelling mistakes, grammatical errors documentation directly using GitHub web interface, long changes made source file. generally means ’ll need edit roxygen2 comments .R, .Rd file. can find .R file generates .Rd reading comment first line.","code":""},{"path":"http://xml2.r-lib.org/dev/CONTRIBUTING.html","id":"bigger-changes","dir":"","previous_headings":"","what":"Bigger changes","title":"Contributing to xml2","text":"want make bigger change, ’s good idea first file issue make sure someone team agrees ’s needed. ’ve found bug, please file issue illustrates bug minimal reprex (also help write unit test, needed).","code":""},{"path":"http://xml2.r-lib.org/dev/CONTRIBUTING.html","id":"pull-request-process","dir":"","previous_headings":"Bigger changes","what":"Pull request process","title":"Contributing to xml2","text":"Fork package clone onto computer. haven’t done , recommend using usethis::create_from_github(\"r-lib/xml2\", fork = TRUE). Install development dependences devtools::install_dev_deps(), make sure package passes R CMD check running devtools::check(). R CMD check doesn’t pass cleanly, ’s good idea ask help continuing. Create Git branch pull request (PR). recommend using usethis::pr_init(\"brief-description--change\"). Make changes, commit git, create PR running usethis::pr_push(), following prompts browser. title PR briefly describe change. body PR contain Fixes #issue-number. user-facing changes, add bullet top NEWS.md (.e. just first header). Follow style described https://style.tidyverse.org/news.html.","code":""},{"path":"http://xml2.r-lib.org/dev/CONTRIBUTING.html","id":"code-style","dir":"","previous_headings":"Bigger changes","what":"Code style","title":"Contributing to xml2","text":"New code follow tidyverse style guide. can use styler package apply styles, please don’t restyle code nothing PR. use roxygen2, Markdown syntax, documentation. use testthat unit tests. Contributions test cases included easier accept.","code":""},{"path":"http://xml2.r-lib.org/dev/CONTRIBUTING.html","id":"code-of-conduct","dir":"","previous_headings":"","what":"Code of Conduct","title":"Contributing to xml2","text":"Please note xml2 project released Contributor Code Conduct. contributing project agree abide terms.","code":""},{"path":[]},{"path":"http://xml2.r-lib.org/dev/ISSUE_TEMPLATE.html","id":"reproducible-example","dir":"","previous_headings":"","what":"Reproducible Example","title":"NA","text":"","code":"devtools::session_info() # Paste output below #> output"},{"path":"http://xml2.r-lib.org/dev/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"MIT License","title":"MIT License","text":"Copyright (c) 2023 xml2 authors Permission hereby granted, free charge, person obtaining copy software associated documentation files (“Software”), deal Software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, /sell copies Software, permit persons Software furnished , subject following conditions: copyright notice permission notice shall included copies substantial portions Software. SOFTWARE PROVIDED “”, WITHOUT WARRANTY KIND, EXPRESS IMPLIED, INCLUDING LIMITED WARRANTIES MERCHANTABILITY, FITNESS PARTICULAR PURPOSE NONINFRINGEMENT. EVENT SHALL AUTHORS COPYRIGHT HOLDERS LIABLE CLAIM, DAMAGES LIABILITY, WHETHER ACTION CONTRACT, TORT OTHERWISE, ARISING , CONNECTION SOFTWARE USE DEALINGS SOFTWARE.","code":""},{"path":"http://xml2.r-lib.org/dev/SUPPORT.html","id":null,"dir":"","previous_headings":"","what":"Getting help with xml2","title":"Getting help with xml2","text":"Thanks using xml2! filing issue, places explore pieces put together make process smooth possible.","code":""},{"path":"http://xml2.r-lib.org/dev/SUPPORT.html","id":"make-a-reprex","dir":"","previous_headings":"","what":"Make a reprex","title":"Getting help with xml2","text":"Start making minimal reproducible example using reprex package. haven’t heard used reprex , ’re treat! Seriously, reprex make R-question-asking endeavors easier (pretty insane ROI five ten minutes ’ll take learn ’s ). additional reprex pointers, check Get help! section tidyverse site.","code":""},{"path":"http://xml2.r-lib.org/dev/SUPPORT.html","id":"where-to-ask","dir":"","previous_headings":"","what":"Where to ask?","title":"Getting help with xml2","text":"Armed reprex, next step figure ask. ’s question: start community.rstudio.com, /StackOverflow. people answer questions. ’s bug: ’re right place, file issue. ’re sure: let community help figure ! problem bug feature request, can easily return report . opening new issue, sure search issues pull requests make sure bug hasn’t reported /already fixed development version. default, search pre-populated :issue :open. can edit qualifiers (e.g. :pr, :closed) needed. example, ’d simply remove :open search issues repo, open closed.","code":""},{"path":"http://xml2.r-lib.org/dev/SUPPORT.html","id":"what-happens-next","dir":"","previous_headings":"","what":"What happens next?","title":"Getting help with xml2","text":"efficient possible, development tidyverse packages tends bursty, shouldn’t worry don’t get immediate response. Typically don’t look repo sufficient quantity issues accumulates, ’s burst intense activity focus efforts. makes development efficient avoids expensive context switching problems, cost taking longer get back . process makes good reprex particularly important might multiple months initial report start working . can’t reproduce bug, can’t fix !","code":""},{"path":"http://xml2.r-lib.org/dev/articles/modification.html","id":"modifying-existing-xml","dir":"Articles","previous_headings":"","what":"Modifying Existing XML","title":"Node Modification","text":"Modifying existing XML can done xml2 using replacement functions accessors. methods individual xml_node objects well xml_nodeset objects. vector values provided applied piecewise nodeset, otherwise value recycled.","code":""},{"path":"http://xml2.r-lib.org/dev/articles/modification.html","id":"text-modification","dir":"Articles","previous_headings":"Modifying Existing XML","what":"Text Modification","title":"Node Modification","text":"Text modification happens text nodes. given node one text node first affected. want modify additional text nodes need select explicitly /text().","code":"x <- read_xml(\"

This is some text<\/b>. This is more.<\/p>\") xml_text(x) #> [1] \"This is some text. This is more.\" xml_text(x) <- \"This is some other text.\" xml_text(x) #> [1] \"This is some other text.text. This is more.\" # You can avoid this by explicitly selecting the text node. x <- read_xml(\"

This is some text. This is bold!<\/b><\/p>\") text_only <- xml_find_all(x, \"//text()\") xml_text(text_only) <- c(\"This is some other text. \", \"Still bold!\") xml_text(x) #> [1] \"This is some other text. Still bold!\" xml_structure(x) #>

#> {text} #> #> {text}"},{"path":"http://xml2.r-lib.org/dev/articles/modification.html","id":"attribute-and-namespace-definition-modification","dir":"Articles","previous_headings":"Modifying Existing XML","what":"Attribute and Namespace Definition Modification","title":"Node Modification","text":"Attributes namespace definitions modified one time xml_attr() xml_attrs(). cases using NULL value remove attribute completely.","code":"x <- read_xml(\"xml2<\/a>\") xml_attr(x, \"href\") #> [1] \"invalid!\" xml_attr(x, \"href\") <- \"https://github.com/r-lib/xml2\" xml_attr(x, \"href\") #> [1] \"https://github.com/r-lib/xml2\" xml_attrs(x) <- c(id = \"xml2\", href = \"https://github.com/r-lib/xml2\") xml_attrs(x) #> href id #> \"https://github.com/r-lib/xml2\" \"xml2\" x #> {xml_document} #> xml_attrs(x) <- NULL x #> {xml_document} #> # Namespaces are added with as a xmlns or xmlns:prefix attribute xml_attr(x, \"xmlns\") <- \"http://foo\" x #> {xml_document} #> xml_attr(x, \"xmlns:bar\") <- \"http://bar\" x #> {xml_document} #> "},{"path":"http://xml2.r-lib.org/dev/articles/modification.html","id":"name-modification","dir":"Articles","previous_headings":"Modifying Existing XML","what":"Name Modification","title":"Node Modification","text":"Node names modified xml_name().","code":"x <- read_xml(\"<\/a>\") x #> {xml_document} #> #> [1] xml_name(x) #> [1] \"a\" xml_name(x) <- \"c\" x #> {xml_document} #> #> [1] "},{"path":"http://xml2.r-lib.org/dev/articles/modification.html","id":"node-modification","dir":"Articles","previous_headings":"","what":"Node modification","title":"Node Modification","text":"functions .copy argument. set FALSE remove new node location inserting new location. Otherwise make copy node insertion.","code":""},{"path":"http://xml2.r-lib.org/dev/articles/modification.html","id":"replacing-existing-nodes","dir":"Articles","previous_headings":"Node modification","what":"Replacing existing nodes","title":"Node Modification","text":"","code":"x <- read_xml(\"1<\/child>23<\/child><\/child><\/parent>\") children <- xml_children(x) t1 <- children[[1]] t2 <- children[[2]] t3 <- xml_children(children[[2]])[[1]] xml_replace(t1, t3) #> {xml_node} #> x #> {xml_document} #> #> [1] 3<\/child> #> [2] 23<\/child><\/child>"},{"path":"http://xml2.r-lib.org/dev/articles/modification.html","id":"add-a-sibling","dir":"Articles","previous_headings":"Node modification","what":"Add a sibling","title":"Node Modification","text":"","code":"x <- read_xml(\"1<\/child>23<\/child><\/child><\/parent>\") children <- xml_children(x) t1 <- children[[1]] t2 <- children[[2]] t3 <- xml_children(children[[2]])[[1]] xml_add_sibling(t1, t3) x #> {xml_document} #> #> [1] 1<\/child> #> [2] 3<\/child> #> [3] 23<\/child><\/child> xml_add_sibling(t3, t1, where = \"before\") x #> {xml_document} #> #> [1] 1<\/child> #> [2] 3<\/child> #> [3] 23<\/child>1<\/child><\/child>"},{"path":"http://xml2.r-lib.org/dev/articles/modification.html","id":"add-a-child","dir":"Articles","previous_headings":"Node modification","what":"Add a child","title":"Node Modification","text":"","code":"x <- read_xml(\"1<\/child>23<\/child><\/child><\/parent>\") children <- xml_children(x) t1 <- children[[1]] t2 <- children[[2]] t3 <- xml_children(children[[2]])[[1]] xml_add_child(t1, t3) x #> {xml_document} #> #> [1] 13<\/child><\/child> #> [2] 23<\/child><\/child> xml_add_child(t1, read_xml(\"\")) x #> {xml_document} #> #> [1] 13<\/child><\/child> #> [2] 23<\/child><\/child>"},{"path":"http://xml2.r-lib.org/dev/articles/modification.html","id":"removing-nodes","dir":"Articles","previous_headings":"Node modification","what":"Removing nodes","title":"Node Modification","text":"xml_remove() can used remove node (children) tree. default behavior unlink node tree, free memory node, R objects pointing node still valid. allows code like following work without crashing R planning referencing nodes memory wasted. Calling xml_remove(free = TRUE) remove nodes free memory used store . Note case node previously pointed node children instead pointing free memory may cause R crash. xml2 can’t figure , ’s responsibility remove objects longer valid. particular xml_find_*() results easy overlook, example","code":"x <- read_xml(\"<\/bar><\/foo>\") x1 <- x %>% xml_children() %>% .[[1]] x2 <- x1 %>% xml_children() %>% .[[1]] xml_remove(x1) rm(x1) gc() #> used (Mb) gc trigger (Mb) max used (Mb) #> Ncells 672184 35.9 1326505 70.9 1326505 70.9 #> Vcells 1167942 9.0 8388608 64.0 2566051 19.6 x2 #> {xml_node} #> x <- read_xml(\"<\/b><\/a>\") bees <- xml_find_all(x, \"//b\") xml_remove(xml_child(x), free = TRUE) # bees[[1]] is no longer valid!!! rm(bees) gc() #> used (Mb) gc trigger (Mb) max used (Mb) #> Ncells 672191 35.9 1326505 70.9 1326505 70.9 #> Vcells 1167944 9.0 8388608 64.0 2566051 19.6"},{"path":"http://xml2.r-lib.org/dev/articles/modification.html","id":"namespaces","dir":"Articles","previous_headings":"Node modification","what":"Namespaces","title":"Node Modification","text":"want construct document following namespace layout. (https://stackoverflow.com/questions/32939229/creating-xml--r--namespaces/32941524#32941524).","code":" My Layer<\/se:Name> <\/layer> <\/sld> d <- xml_new_root(\"sld\", \"xmlns\" = \"http://www.opengis.net/sld\", \"xmlns:ogc\" = \"http://www.opengis.net/ogc\", \"xmlns:se\" = \"http://www.opengis.net//se\", version = \"1.1.0\" ) %>% xml_add_child(\"layer\") %>% xml_add_child(\"se:Name\", \"My Layer\") %>% xml_root() d #> {xml_document} #> #> [1] \\n My Layer<\/se:Name>\\n<\/layer>"},{"path":"http://xml2.r-lib.org/dev/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Hadley Wickham. Author, maintainer. Jim Hester. Author. Jeroen Ooms. Author. . Copyright holder, funder. R Foundation. Contributor. Copy R-project homepage cached example","code":""},{"path":"http://xml2.r-lib.org/dev/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Wickham H, Hester J, Ooms J (2024). xml2: Parse XML. R package version 1.3.6.9000, https://github.com/r-lib/xml2, https://xml2.r-lib.org/.","code":"@Manual{, title = {xml2: Parse XML}, author = {Hadley Wickham and Jim Hester and Jeroen Ooms}, year = {2024}, note = {R package version 1.3.6.9000, https://github.com/r-lib/xml2}, url = {https://xml2.r-lib.org/}, }"},{"path":"http://xml2.r-lib.org/dev/index.html","id":"xml2","dir":"","previous_headings":"","what":"Parse XML","title":"Parse XML","text":"xml2 package binding libxml2, making easy work HTML XML R. API somewhat inspired jQuery.","code":""},{"path":"http://xml2.r-lib.org/dev/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Parse XML","text":"can install xml2 CRAN, can install development version github, using devtools:","code":"install.packages(\"xml2\") # install.packages(\"pak\") pak::pak(\"r-lib/xml2\")"},{"path":"http://xml2.r-lib.org/dev/index.html","id":"usage","dir":"","previous_headings":"","what":"Usage","title":"Parse XML","text":"three key classes: xml_node: single node document. xml_doc: complete document. Acting document usually acting root node document. xml_nodeset: set nodes within document. Operations xml_nodesets vectorised, apply operation node set.","code":"library(\"xml2\") x <- read_xml(\" 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<title><\/html>\") #> {html_document} #> <html> #> [1] <head>\\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset ... read_html(\"<html><title>Hi\") #> {html_document} #> <html> #> [1] <head>\\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset ... # From a local path read_html(system.file(\"extdata\", \"r-project.html\", package = \"xml2\")) #> {html_document} #> <html lang=\"en\"> #> [1] <head>\\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset ... #> [2] <body>\\n <div class=\"container page\">\\n <div class=\"row\">\\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(\"<p>Hi!<\/p>\") tmp <- tempfile(fileext = \".xml\") write_xml(h, tmp, options = \"format\") readLines(tmp) #> [1] \"<!DOCTYPE html PUBLIC \\\"-//W3C//DTD HTML 4.0 Transitional//EN\\\" \\\"http://www.w3.org/TR/REC-html40/loose.dtd\\\">\" #> [2] \"<html><body><p>Hi!<\/p><\/body><\/html>\" # write formatted HTML output write_html(h, tmp, options = \"format\") readLines(tmp) #> [1] \"<!DOCTYPE html PUBLIC \\\"-//W3C//DTD HTML 4.0 Transitional//EN\\\" \\\"http://www.w3.org/TR/REC-html40/loose.dtd\\\">\" #> [2] \"<html><body><p>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 id='1'><child id ='a' /><child id='b' d='b'/><\/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] <child id=\"a\"/> #> [2] <child id=\"b\" d=\"b\"/> 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 xmlns:b=\"http://bar.com\" xmlns:f=\"http://foo.com\"> <doc b:id=\"b\" f:id=\"f\" id=\"\" /> <\/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 <![CDATA[","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_cdata.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Construct a cdata node — xml_cdata","text":"","code":"x <- xml_new_root(\"root\") xml_add_child(x, xml_cdata(\"<d/>\")) as.character(x) #> [1] \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?>\\n<root><![CDATA[<d/>]]><\/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(\"<foo> <bar><boo /><\/bar> <baz/> <\/foo>\") xml_children(x) #> {xml_nodeset (2)} #> [1] <bar>\\n <boo/>\\n<\/bar> #> [2] <baz/> xml_children(xml_children(x)) #> {xml_nodeset (1)} #> [1] <boo/> xml_siblings(xml_children(x)[[1]]) #> {xml_nodeset (1)} #> [1] <baz/> # Note the each unique node only appears once in the output xml_parent(xml_children(x)) #> {xml_nodeset (1)} #> [1] <foo>\\n <bar>\\n <boo/>\\n <\/bar>\\n <baz/>\\n<\/foo> # Mixed content x <- read_xml(\"<foo> a <b/> c <d>e<\/d> f<\/foo>\") # Childen gets the elements, contents gets all node types xml_children(x) #> {xml_nodeset (2)} #> [1] <b/> #> [2] <d>e<\/d> xml_contents(x) #> {xml_nodeset (5)} #> [1] a #> [2] <b/> #> [3] c #> [4] <d>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} #> <b> xml_child(x, 2) #> {xml_node} #> <d> xml_child(x, \"baz\") #> {xml_missing} #> <NA>"},{"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] \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?>\\n<root>\\n <!--Hello!-->\\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( '<!DOCTYPE doc [ <!ELEMENT doc (#PCDATA)> <!ENTITY foo \" test \"> ]> <doc>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(\"<foo><bar><baz/><\/bar><baz/><\/foo>\") xml_find_all(x, \".//baz\") #> {xml_nodeset (2)} #> [1] <baz/> #> [2] <baz/> 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] <bar>\\n <baz/>\\n<\/bar> xml_find_all(bar, \".//baz\") #> {xml_nodeset (1)} #> [1] <baz/> xml_find_all(bar, \"//baz\") #> {xml_nodeset (2)} #> [1] <baz/> #> [2] <baz/> # Find all vs find one ----------------------------------------------------- x <- read_xml(\"<body> <p>Some <b>text<\/b>.<\/p> <p>Some <b>other<\/b> <b>text<\/b>.<\/p> <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] <b>text<\/b> #> [2] <b>other<\/b> #> [3] <b>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] <b>text<\/b> #> #> [[2]] #> {xml_nodeset (2)} #> [1] <b>other<\/b> #> [2] <b>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] <b>text<\/b> #> [2] <b>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(' <root xmlns:f = \"http://foo.com\" xmlns:g = \"http://bar.com\"> <f:doc><g:baz /><\/f:doc> <f:doc><g:baz /><\/f:doc> <\/root> ') xml_find_all(x, \".//f:doc\") #> {xml_nodeset (2)} #> [1] <f:doc>\\n <g:baz/>\\n<\/f:doc> #> [2] <f:doc>\\n <g:baz/>\\n<\/f:doc> xml_find_all(x, \".//f:doc\", xml_ns(x)) #> {xml_nodeset (2)} #> [1] <f:doc>\\n <g:baz/>\\n<\/f:doc> #> [2] <f:doc>\\n <g:baz/>\\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(\"<bar>123<\/bar>\") xml_name(x) #> [1] \"bar\" y <- read_xml(\"<bar><baz>1<\/baz>abc<foo /><\/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(' <root> <doc1 xmlns = \"http://foo.com\"><baz /><\/doc1> <doc2 xmlns = \"http://bar.com\"><baz /><\/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] <baz/> 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( \"<foo xmlns = 'http://foo.com'> <baz/> <bar xmlns = 'http://bar.com'> <baz/> <\/bar> <\/foo>\" ) # Need to specify the default namespaces to find the baz nodes xml_find_all(x, \"//d1:baz\") #> {xml_nodeset (1)} #> [1] <baz/> xml_find_all(x, \"//d2:baz\") #> {xml_nodeset (1)} #> [1] <baz/> # 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] <baz/> #> [2] <baz/>"},{"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(\"<foo><bar><baz /><\/bar><baz /><\/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(\"<a> <b><c>123<\/c><\/b> <b><c>456<\/c><\/b> <\/a>\") b <- xml_find_all(x, \"//b\") out <- xml_serialize(b, NULL) xml_unserialize(out) #> {xml_nodeset (2)} #> [1] <b>\\n <c>123<\/c>\\n<\/b> #> [2] <b>\\n <c>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(\"<a><b><c/><c/><\/b><d/><\/a>\")) #> <a> #> <b> #> <c> #> <c> #> <d> rproj <- read_html(system.file(\"extdata\", \"r-project.html\", package = \"xml2\")) xml_structure(rproj) #> <html [lang]> #> <head> #> <meta [charset]> #> <meta [http-equiv, content]> #> <meta [name, content]> #> <title> #> {text} #> <link [rel, type, href, sizes]> #> <link [rel, type, href, sizes]> #> {comment} #> <link [href, rel]> #> <link [href, rel]> #> {comment} #> {comment} #> {comment} #> <body> #> {text} #> <div [class]> #> {text} #> <div [class]> #> {text} #> <div [class, role]> #> {text} #> <div [class]> #> {text} #> <div [class]> #> {text} #> <p> #> <a [href]> #> <img [src, alt]> #> {text} #> <p> #> <small> #> <a [href]> #> {text} #> {text} #> <h2> #> {text} #> {text} #> <p> #> <a [href]> #> {text} #> {text} #> <h2> #> {text} #> {text} #> <ul> #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> {text} #> <div [class]> #> {text} #> <h2> #> {text} #> {text} #> <ul> #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> {text} #> <div [class]> #> {text} #> <h2> #> {text} #> {text} #> <ul> #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> {text} #> <div [class]> #> {text} #> <h2> #> {text} #> {text} #> <ul> #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> {text} #> {text} #> {text} #> <div [class]> #> {text} #> <h1> #> {text} #> {text} #> <h2 [id]> #> {text} #> {text} #> <p> #> {text} #> <strong> #> <a [href]> #> {text} #> {text} #> <a [href]> #> {text} #> {text} #> {text} #> <p> #> {text} #> <a [href]> #> {text} #> {text} #> {text} #> <h2 [id]> #> {text} #> {text} #> <ul> #> <li> #> <p> #> <a [href]> #> <strong> #> {text} #> {text} #> {text} #> <li> #> <p> #> <strong> #> {text} #> {text} #> {text} #> <li> #> <p> #> <a [href]> #> <strong> #> {text} #> {text} #> {text} #> <li> #> <p> #> <strong> #> {text} #> {text} #> {text} #> <li> #> <p> #> <strong> #> <a [href]> #> {text} #> {text} #> {text} #> <li> #> <p> #> <strong> #> <a [href]> #> {text} #> {text} #> {text} #> {comment} #> {text} #> {text} #> <div [class]> #> {text} #> {text} #> {text} #> {comment} #> {text} #> <script [src]> #> {comment} #> <script [src]> xml_structure(xml_find_all(rproj, \".//p\")) #> [[1]] #> <p> #> <a [href]> #> <img [src, alt]> #> #> [[2]] #> <p> #> <small> #> <a [href]> #> {text} #> #> [[3]] #> <p> #> <a [href]> #> {text} #> #> [[4]] #> <p> #> {text} #> <strong> #> <a [href]> #> {text} #> {text} #> <a [href]> #> {text} #> {text} #> #> [[5]] #> <p> #> {text} #> <a [href]> #> {text} #> {text} #> #> [[6]] #> <p> #> <a [href]> #> <strong> #> {text} #> {text} #> #> [[7]] #> <p> #> <strong> #> {text} #> {text} #> #> [[8]] #> <p> #> <a [href]> #> <strong> #> {text} #> {text} #> #> [[9]] #> <p> #> <strong> #> {text} #> {text} #> #> [[10]] #> <p> #> <strong> #> <a [href]> #> {text} #> {text} #> #> [[11]] #> <p> #> <strong> #> <a [href]> #> {text} #> {text} #> h <- read_html(\"<body><p id = 'a'><\/p><p class = 'c d'><\/p><\/body>\") html_structure(h) #> <html> #> <body> #> <p#a> #> <p.c.d>"},{"path":"http://xml2.r-lib.org/dev/reference/xml_text.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract or modify the text — xml_text","title":"Extract or modify the text — xml_text","text":"xml_text returns character vector, xml_double returns numeric vector, xml_integer returns integer vector.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_text.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract or modify the text — xml_text","text":"","code":"xml_text(x, trim = FALSE) xml_text(x) <- value xml_set_text(x, value) xml_double(x) xml_integer(x)"},{"path":"http://xml2.r-lib.org/dev/reference/xml_text.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract or modify the text — xml_text","text":"x document, node, node set. trim TRUE trim leading trailing spaces. value character vector replacement text.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_text.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract or modify the text — xml_text","text":"character vector, length x.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_text.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract or modify the text — xml_text","text":"","code":"x <- read_xml(\"<p>This is some text. This is <b>bold!<\/b><\/p>\") xml_text(x) #> [1] \"This is some text. This is bold!\" xml_text(xml_children(x)) #> [1] \"bold!\" x <- read_xml(\"<x>This is some text. <x>This is some nested text.<\/x><\/x>\") xml_text(x) #> [1] \"This is some text. This is some nested text.\" xml_text(xml_find_all(x, \"//x\")) #> [1] \"This is some text. This is some nested text.\" #> [2] \"This is some nested text.\" x <- read_xml(\"<p> Some text <\/p>\") xml_text(x, trim = TRUE) #> [1] \"Some text\" # xml_double() and xml_integer() are useful for extracting numeric attributes x <- read_xml(\"<plot><point x='1' y='2' /><point x='2' y='1' /><\/plot>\") xml_integer(xml_find_all(x, \"//@x\")) #> [1] 1 2"},{"path":"http://xml2.r-lib.org/dev/reference/xml_type.html","id":null,"dir":"Reference","previous_headings":"","what":"Determine the type of a node. — xml_type","title":"Determine the type of a node. — xml_type","text":"Determine type node.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_type.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Determine the type of a node. — xml_type","text":"","code":"xml_type(x)"},{"path":"http://xml2.r-lib.org/dev/reference/xml_type.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Determine the type of a node. — xml_type","text":"x document, node, node set.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_type.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Determine the type of a node. — xml_type","text":"","code":"x <- read_xml(\"<foo> a <b /> <![CDATA[ blah]]><\/foo>\") xml_type(x) #> [1] \"element\" xml_type(xml_contents(x)) #> [1] \"text\" \"element\" \"text\" \"cdata\""},{"path":"http://xml2.r-lib.org/dev/reference/xml_url.html","id":null,"dir":"Reference","previous_headings":"","what":"The URL of an XML document — xml_url","title":"The URL of an XML document — xml_url","text":"useful interpreting relative urls url_relative().","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_url.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"The URL of an XML document — xml_url","text":"","code":"xml_url(x)"},{"path":"http://xml2.r-lib.org/dev/reference/xml_url.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"The URL of an XML document — xml_url","text":"x node document.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_url.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"The URL of an XML document — xml_url","text":"character vector length 1. Returns NA name set.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_url.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"The URL of an XML document — xml_url","text":"","code":"catalog <- read_xml(xml2_example(\"cd_catalog.xml\")) xml_url(catalog) #> [1] \"/home/runner/work/_temp/Library/xml2/extdata/cd_catalog.xml\" x <- read_xml(\"<foo/>\") xml_url(x) #> [1] NA"},{"path":"http://xml2.r-lib.org/dev/reference/xml_validate.html","id":null,"dir":"Reference","previous_headings":"","what":"Validate XML schema — xml_validate","title":"Validate XML schema — xml_validate","text":"Validate XML document XML 1.0 schema.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_validate.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Validate XML schema — xml_validate","text":"","code":"xml_validate(x, schema)"},{"path":"http://xml2.r-lib.org/dev/reference/xml_validate.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Validate XML schema — xml_validate","text":"x document, node, node set. schema XML document containing schema","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_validate.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Validate XML schema — xml_validate","text":"TRUE FALSE","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_validate.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Validate XML schema — xml_validate","text":"","code":"# Example from https://msdn.microsoft.com/en-us/library/ms256129(v=vs.110).aspx doc <- read_xml(system.file(\"extdata/order-doc.xml\", package = \"xml2\")) schema <- read_xml(system.file(\"extdata/order-schema.xml\", package = \"xml2\")) xml_validate(doc, schema) #> [1] TRUE #> attr(,\"errors\") #> character(0)"},{"path":[]},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-136","dir":"Changelog","previous_headings":"","what":"xml2 1.3.6","title":"xml2 1.3.6","text":"CRAN release: 2023-12-04 Now compatible libxml2 2.12.0 later (@KNnut). Fixed format string issues detected R-devel. Remove unused dependencies glue, withr lifecycle (@mgirlich). print() faster long xml_nodeset inputs (#366, @michaelchirico). xml_attr(), xml_attrs(), xml_double(), xml_integer(), xml_length(), xml_name(), xml_path(), xml_text(), xml_type() longer use S3 dispatch instead dispatch C, leading considerable performance improvements many cases (@mgirlich, #400). xml_find_int() analogous xml_find_num() returning integers matched XPath (#365, @michaelchirico). xml_serialize() now includes document type xml_unserialize() works also HTML documents (#407, @HenrikBengtsson).","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-135","dir":"Changelog","previous_headings":"","what":"xml2 1.3.5","title":"xml2 1.3.5","text":"CRAN release: 2023-07-06 Small speedup xml_find_all() (@mgirlich, #393). Fixes R CMD check problems.","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-134","dir":"Changelog","previous_headings":"","what":"xml2 1.3.4","title":"xml2 1.3.4","text":"CRAN release: 2023-04-27 Fixes R CMD check problems. Windows: update libxml2 2.10.3","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-133","dir":"Changelog","previous_headings":"","what":"xml2 1.3.3","title":"xml2 1.3.3","text":"CRAN release: 2021-11-30 Hadley Wickham now () maintainer. xml2 re-licensed MIT (#317). xml_find_all.xml_node() fails informatively xpath parameter wrong type (@michaelchirico) xml_find_all.xml_nodeset() gains flatten argument control whether return single nodeset list nodesets (#311, @jakejh) write_xml() write_html() now return NULL invisibly, prior version 1.3.0 (#307) XPtr gets explicit copy constructor assignment operator definitions, two missing components Rule three (@michaelchirico) Windows: update libxml2 2.9.10 libxslt 1.1.34 add ucrt libs","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-132","dir":"Changelog","previous_headings":"","what":"xml2 1.3.2","title":"xml2 1.3.2","text":"CRAN release: 2020-04-23 read_html() read_xml() now error passed strings length greater one (#121) read_xml.raw() inadvertent regression 1.3.0 now fixed (#300) Compilation fix macOS 10.15.4 (@kevinushey, #296)","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-131","dir":"Changelog","previous_headings":"","what":"xml2 1.3.1","title":"xml2 1.3.1","text":"CRAN release: 2020-04-09 read_html() now works HTML files non-ASCII encodings (#293).","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-130","dir":"Changelog","previous_headings":"","what":"xml2 1.3.0","title":"xml2 1.3.0","text":"CRAN release: 2020-04-01 Removes Rcpp dependency","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-125","dir":"Changelog","previous_headings":"","what":"xml2 1.2.5","title":"xml2 1.2.5","text":"CRAN release: 2020-03-11 Fix compilation issue macOS versions High Sierra using homebrew supplied libxml2","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-124","dir":"Changelog","previous_headings":"","what":"xml2 1.2.4","title":"xml2 1.2.4","text":"CRAN release: 2020-03-10 Fix potential dangling pointer internal asXmlChar() function (@michaelquinn32, #287). as_xml_document() now handles cases text nodes trailing normal nodes (#274). xml_add_child() can now create nodes par attribute. previously errored due partial name matching parent function internal create_node() function. (@jennybc, #285) libxml2_version() now returns semantic version rather alphanumeric version, “2.9.10” > “2.9.9” (#277)","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-122","dir":"Changelog","previous_headings":"","what":"xml2 1.2.2","title":"xml2 1.2.2","text":"CRAN release: 2019-08-09 Export S4 classes documentation, can used packages without Warnings (@nuest, #267)","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-121","dir":"Changelog","previous_headings":"","what":"xml2 1.2.1","title":"xml2 1.2.1","text":"CRAN release: 2019-07-29","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"new-features-1-2-1","dir":"Changelog","previous_headings":"","what":"New Features","title":"xml2 1.2.1","text":"xml2 now pkgdown site! https://xml2.r-lib.org (@jayhesselberth, #211). Windows: upgrade libxml2 2.9.8 print methods now match type document, e.g. read_html() prints “{html_document}” rather “{xml_document}” (#227)","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"bugfixes-and-miscellaneous-features-1-2-1","dir":"Changelog","previous_headings":"","what":"Bugfixes and Miscellaneous features","title":"xml2 1.2.1","text":"Generic xml2 error now forwarded R errors. Previously errors output stderr, suppressed (#209). Fix ICU 59+ defaulting use char16_t, available C++11 (#231) longer uses C connections API Better error message trying run download_xml() without curl package installed (#262) xml2 classes now registered use S4 calling setOldClass() (#248) Nodes nested data type definition entities now work without crashing (#241) Test failure fixed due behavior change relative paths libxml2 2.9.9 (#245). read_xml() now better error message given zero length character inputs (#212). read_xml() read_html() now automatically check response succeeded trying read HTTP response (#255). xml_root() can now create root nodes namespaces (#239) xml_set_attr() longer crashes try set namespace node multiple times (#253). xml_set_attr() now recycles values needed (#221) xml_structure() gains file argument, support writing file rather console (#244).","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-120","dir":"Changelog","previous_headings":"","what":"xml2 1.2.0","title":"xml2 1.2.0","text":"CRAN release: 2018-01-24","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"breaking-changes-1-2-0","dir":"Changelog","previous_headings":"","what":"Breaking changes","title":"xml2 1.2.0","text":"as_list() xml_document objects properly include root node returned list. Previous behavior can obtained using as_list()[[1L]] place as_list().","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"new-features-1-2-0","dir":"Changelog","previous_headings":"","what":"New Features","title":"xml2 1.2.0","text":"download_xml() download_html() helper functions make easy download files (#193). xml_attr() can now set attributes value (#198). xml_serialize() xml_unserialize() now create file connections given character input (#179).","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"bugfixes-1-2-0","dir":"Changelog","previous_headings":"","what":"Bugfixes","title":"xml2 1.2.0","text":"xml_find_first() longer de-duplicates results, results always length inputs (documented) (#194). xml2 can now build using libxml2 2.7.0 Use Rcpp symbol registration visibility prevent symbol conflicts Linux xml_add_child() now requires less resources insert node called .= 0L (@heckendorfc, #175). Fixed failing examples due change external resource.","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-111","dir":"Changelog","previous_headings":"","what":"xml2 1.1.1","title":"xml2 1.1.1","text":"CRAN release: 2017-01-24 small point release addressing installation issues found older libxml2 versions shipped RedHat Linux 6 / CentOS 6 (#163, #164).","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-110","dir":"Changelog","previous_headings":"","what":"xml2 1.1.0","title":"xml2 1.1.0","text":"CRAN release: 2017-01-07","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"new-features-1-1-0","dir":"Changelog","previous_headings":"","what":"New Features","title":"xml2 1.1.0","text":"write_xml() write_html() now accept connections well filenames output. (#157) xml_add_child() now takes .argument specifying add new children. (#138) as_xml() generic function convert R objects xml. important method lists enables full roundtrip support going back xml lists enables full roundtrip support XML. (#137, #143) xml_new_root() can used create new document root node one step (#131). xml_add_parent() inserts new node node parent (#129) Add xml_validate() validate document xml schema (#31, @jeroenooms). Export xml2_types.h allow extension packages xslt. xml_comment() allows add comment nodes document. (#111) xml_cdata() allows add CDATA nodes document. (#128) Add xml_set_text() xml_set_name() equivalent xml_text<- xml_name<-. (#130). Add xml_set_attr() xml_set_attrs() equivalent xml_attr<- xml_attrs<-. (#109, #130) Add write_html() method (#133).","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"bugfixes-1-1-0","dir":"Changelog","previous_headings":"","what":"Bugfixes","title":"xml2 1.1.0","text":"xml_new_document() now explicitly sets encoding (default UTF-8) (#142) Document formatting options write_xml() (#132) Add missing methods xml_missing objects. (#134) Bugfix xml_length.xml_nodeset caused fail unconditionally. (#140) .na() now returns TRUE xml_missing objects. (#139) Trim non-breaking spaces xml_text(trim = TRUE) (#151). Allow setting non-character attributes (values coerced characters). (@sjp, #117, #122). Fixed return value call vapply xml_integer.xml_nodeset. (@ddiez, #146, #147). Allow docs missing root element created printed. (@sjp, #126, #121). xml_add_* methods now return invisibly. (@sjp, #124) as_list() now preserves element names attributes exist, escapes XML attributes conflict special R attributes (@peterfoley, #115).","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-100","dir":"Changelog","previous_headings":"","what":"xml2 1.0.0","title":"xml2 1.0.0","text":"CRAN release: 2016-06-24 C++ functions now use checked_get() instead get() possible, NULL XPtrs properly throw error rather crashing. (@jimhester, #101, #104). xml_integer() xml_double() functions make easy extract integer double text nodes (@jimhester, #97, #99). xml2 now supports modification creation XML nodes. New functions xml_new_document(), xml_new_child(), xml_new_sibling(), xml_set_namespace(), , xml_remove(), xml_replace(), xml_root() replacement methods xml_name(), xml_attr(), xml_attrs() xml_text() (@jimhester, #9 #76) xml_ns() now keeps namespace prefixes point URI (@jimhester, #35, #95). read_xml() read_html() methods added httr::response() objects. (@jimhester, #63, #93) xml_child() function make selecting children little easier (@jimhester, #23, #94) xml_find_one() deprecated favor xml_find_first() (@jimhester, #58, #92) xml_read() functions now default passing document’s namespace object. Namespace definitions can now removed well added xml_ns_strip() added remove default namespaces document. (@jimhester, #28, #89) xml_read() gains options argument control available parsing options, including HUGE turn limits parsing large documents now drops blank text nodes default, mimicking default behavior XML package. (@jimhester, #49, #62, #85, #88) xml_write() expands path filenames, directories can specified ‘~/’ (@jimhester, #86, #80) xml_find_one() now returns ‘xml_missing’ node object 0 matches (@jimhester, #55, #53, hadley/rvest#82). xml_find_num(), xml_find_chr(), xml_find_lgl() functions added return numeric, character logical results XPath expressions. (@jimhester, #55) xml_name() xml_text() always correctly encode returned value UTF-8 (#54).","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-012","dir":"Changelog","previous_headings":"","what":"xml2 0.1.2","title":"xml2 0.1.2","text":"CRAN release: 2015-09-01 Improved configure script - now works R-devel windows. Compiles older versions libxml2.,","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-011","dir":"Changelog","previous_headings":"","what":"xml2 0.1.1","title":"xml2 0.1.1","text":"CRAN release: 2015-06-02 Make configure script cross platform. Add xml_length() count number children (#32).","code":""}] +[{"path":[]},{"path":"http://xml2.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"our-pledge","dir":"","previous_headings":"","what":"Our Pledge","title":"Contributor Covenant Code of Conduct","text":"members, contributors, leaders pledge make participation community harassment-free experience everyone, regardless age, body size, visible invisible disability, ethnicity, sex characteristics, gender identity expression, level experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, sexual identity orientation. pledge act interact ways contribute open, welcoming, diverse, inclusive, healthy community.","code":""},{"path":"http://xml2.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"our-standards","dir":"","previous_headings":"","what":"Our Standards","title":"Contributor Covenant Code of Conduct","text":"Examples behavior contributes positive environment community include: Demonstrating empathy kindness toward people respectful differing opinions, viewpoints, experiences Giving gracefully accepting constructive feedback Accepting responsibility apologizing affected mistakes, learning experience Focusing best just us individuals, overall community Examples unacceptable behavior include: use sexualized language imagery, sexual attention advances kind Trolling, insulting derogatory comments, personal political attacks Public private harassment Publishing others’ private information, physical email address, without explicit permission conduct reasonably considered inappropriate professional setting","code":""},{"path":"http://xml2.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement-responsibilities","dir":"","previous_headings":"","what":"Enforcement Responsibilities","title":"Contributor Covenant Code of Conduct","text":"Community leaders responsible clarifying enforcing standards acceptable behavior take appropriate fair corrective action response behavior deem inappropriate, threatening, offensive, harmful. Community leaders right responsibility remove, edit, reject comments, commits, code, wiki edits, issues, contributions aligned Code Conduct, communicate reasons moderation decisions appropriate.","code":""},{"path":"http://xml2.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"scope","dir":"","previous_headings":"","what":"Scope","title":"Contributor Covenant Code of Conduct","text":"Code Conduct applies within community spaces, also applies individual officially representing community public spaces. Examples representing community include using official e-mail address, posting via official social media account, acting appointed representative online offline event.","code":""},{"path":"http://xml2.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement","dir":"","previous_headings":"","what":"Enforcement","title":"Contributor Covenant Code of Conduct","text":"Instances abusive, harassing, otherwise unacceptable behavior may reported community leaders responsible enforcement codeofconduct@posit.co. complaints reviewed investigated promptly fairly. community leaders obligated respect privacy security reporter incident.","code":""},{"path":"http://xml2.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement-guidelines","dir":"","previous_headings":"","what":"Enforcement Guidelines","title":"Contributor Covenant Code of Conduct","text":"Community leaders follow Community Impact Guidelines determining consequences action deem violation Code Conduct:","code":""},{"path":"http://xml2.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_1-correction","dir":"","previous_headings":"Enforcement Guidelines","what":"1. Correction","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Use inappropriate language behavior deemed unprofessional unwelcome community. Consequence: private, written warning community leaders, providing clarity around nature violation explanation behavior inappropriate. public apology may requested.","code":""},{"path":"http://xml2.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_2-warning","dir":"","previous_headings":"Enforcement Guidelines","what":"2. Warning","title":"Contributor Covenant Code of Conduct","text":"Community Impact: violation single incident series actions. Consequence: warning consequences continued behavior. interaction people involved, including unsolicited interaction enforcing Code Conduct, specified period time. includes avoiding interactions community spaces well external channels like social media. Violating terms may lead temporary permanent ban.","code":""},{"path":"http://xml2.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_3-temporary-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"3. Temporary Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: serious violation community standards, including sustained inappropriate behavior. Consequence: temporary ban sort interaction public communication community specified period time. public private interaction people involved, including unsolicited interaction enforcing Code Conduct, allowed period. Violating terms may lead permanent ban.","code":""},{"path":"http://xml2.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_4-permanent-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"4. Permanent Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Demonstrating pattern violation community standards, including sustained inappropriate behavior, harassment individual, aggression toward disparagement classes individuals. Consequence: permanent ban sort public interaction within community.","code":""},{"path":"http://xml2.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"attribution","dir":"","previous_headings":"","what":"Attribution","title":"Contributor Covenant Code of Conduct","text":"Code Conduct adapted Contributor Covenant, version 2.1, available https://www.contributor-covenant.org/version/2/1/code_of_conduct.html. Community Impact Guidelines inspired [Mozilla’s code conduct enforcement ladder][https://github.com/mozilla/inclusion]. answers common questions code conduct, see FAQ https://www.contributor-covenant.org/faq. Translations available https://www.contributor-covenant.org/translations.","code":""},{"path":"http://xml2.r-lib.org/dev/CONTRIBUTING.html","id":null,"dir":"","previous_headings":"","what":"Contributing to xml2","title":"Contributing to xml2","text":"outlines propose change xml2. detailed info contributing , tidyverse packages, please see development contributing guide.","code":""},{"path":"http://xml2.r-lib.org/dev/CONTRIBUTING.html","id":"fixing-typos","dir":"","previous_headings":"","what":"Fixing typos","title":"Contributing to xml2","text":"can fix typos, spelling mistakes, grammatical errors documentation directly using GitHub web interface, long changes made source file. generally means ’ll need edit roxygen2 comments .R, .Rd file. can find .R file generates .Rd reading comment first line.","code":""},{"path":"http://xml2.r-lib.org/dev/CONTRIBUTING.html","id":"bigger-changes","dir":"","previous_headings":"","what":"Bigger changes","title":"Contributing to xml2","text":"want make bigger change, ’s good idea first file issue make sure someone team agrees ’s needed. ’ve found bug, please file issue illustrates bug minimal reprex (also help write unit test, needed).","code":""},{"path":"http://xml2.r-lib.org/dev/CONTRIBUTING.html","id":"pull-request-process","dir":"","previous_headings":"Bigger changes","what":"Pull request process","title":"Contributing to xml2","text":"Fork package clone onto computer. haven’t done , recommend using usethis::create_from_github(\"r-lib/xml2\", fork = TRUE). Install development dependences devtools::install_dev_deps(), make sure package passes R CMD check running devtools::check(). R CMD check doesn’t pass cleanly, ’s good idea ask help continuing. Create Git branch pull request (PR). recommend using usethis::pr_init(\"brief-description--change\"). Make changes, commit git, create PR running usethis::pr_push(), following prompts browser. title PR briefly describe change. body PR contain Fixes #issue-number. user-facing changes, add bullet top NEWS.md (.e. just first header). Follow style described https://style.tidyverse.org/news.html.","code":""},{"path":"http://xml2.r-lib.org/dev/CONTRIBUTING.html","id":"code-style","dir":"","previous_headings":"Bigger changes","what":"Code style","title":"Contributing to xml2","text":"New code follow tidyverse style guide. can use styler package apply styles, please don’t restyle code nothing PR. use roxygen2, Markdown syntax, documentation. use testthat unit tests. Contributions test cases included easier accept.","code":""},{"path":"http://xml2.r-lib.org/dev/CONTRIBUTING.html","id":"code-of-conduct","dir":"","previous_headings":"","what":"Code of Conduct","title":"Contributing to xml2","text":"Please note xml2 project released Contributor Code Conduct. contributing project agree abide terms.","code":""},{"path":[]},{"path":"http://xml2.r-lib.org/dev/ISSUE_TEMPLATE.html","id":"reproducible-example","dir":"","previous_headings":"","what":"Reproducible Example","title":"NA","text":"","code":"devtools::session_info() # Paste output below #> output"},{"path":"http://xml2.r-lib.org/dev/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"MIT License","title":"MIT License","text":"Copyright (c) 2023 xml2 authors Permission hereby granted, free charge, person obtaining copy software associated documentation files (“Software”), deal Software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, /sell copies Software, permit persons Software furnished , subject following conditions: copyright notice permission notice shall included copies substantial portions Software. SOFTWARE PROVIDED “”, WITHOUT WARRANTY KIND, EXPRESS IMPLIED, INCLUDING LIMITED WARRANTIES MERCHANTABILITY, FITNESS PARTICULAR PURPOSE NONINFRINGEMENT. EVENT SHALL AUTHORS COPYRIGHT HOLDERS LIABLE CLAIM, DAMAGES LIABILITY, WHETHER ACTION CONTRACT, TORT OTHERWISE, ARISING , CONNECTION SOFTWARE USE DEALINGS SOFTWARE.","code":""},{"path":"http://xml2.r-lib.org/dev/SUPPORT.html","id":null,"dir":"","previous_headings":"","what":"Getting help with xml2","title":"Getting help with xml2","text":"Thanks using xml2! filing issue, places explore pieces put together make process smooth possible.","code":""},{"path":"http://xml2.r-lib.org/dev/SUPPORT.html","id":"make-a-reprex","dir":"","previous_headings":"","what":"Make a reprex","title":"Getting help with xml2","text":"Start making minimal reproducible example using reprex package. haven’t heard used reprex , ’re treat! Seriously, reprex make R-question-asking endeavors easier (pretty insane ROI five ten minutes ’ll take learn ’s ). additional reprex pointers, check Get help! section tidyverse site.","code":""},{"path":"http://xml2.r-lib.org/dev/SUPPORT.html","id":"where-to-ask","dir":"","previous_headings":"","what":"Where to ask?","title":"Getting help with xml2","text":"Armed reprex, next step figure ask. ’s question: start community.rstudio.com, /StackOverflow. people answer questions. ’s bug: ’re right place, file issue. ’re sure: let community help figure ! problem bug feature request, can easily return report . opening new issue, sure search issues pull requests make sure bug hasn’t reported /already fixed development version. default, search pre-populated :issue :open. can edit qualifiers (e.g. :pr, :closed) needed. example, ’d simply remove :open search issues repo, open closed.","code":""},{"path":"http://xml2.r-lib.org/dev/SUPPORT.html","id":"what-happens-next","dir":"","previous_headings":"","what":"What happens next?","title":"Getting help with xml2","text":"efficient possible, development tidyverse packages tends bursty, shouldn’t worry don’t get immediate response. Typically don’t look repo sufficient quantity issues accumulates, ’s burst intense activity focus efforts. makes development efficient avoids expensive context switching problems, cost taking longer get back . process makes good reprex particularly important might multiple months initial report start working . can’t reproduce bug, can’t fix !","code":""},{"path":"http://xml2.r-lib.org/dev/articles/modification.html","id":"modifying-existing-xml","dir":"Articles","previous_headings":"","what":"Modifying Existing XML","title":"Node Modification","text":"Modifying existing XML can done xml2 using replacement functions accessors. methods individual xml_node objects well xml_nodeset objects. vector values provided applied piecewise nodeset, otherwise value recycled.","code":""},{"path":"http://xml2.r-lib.org/dev/articles/modification.html","id":"text-modification","dir":"Articles","previous_headings":"Modifying Existing XML","what":"Text Modification","title":"Node Modification","text":"Text modification happens text nodes. given node one text node first affected. want modify additional text nodes need select explicitly /text().","code":"x <- read_xml(\"<p>This is some <b>text<\/b>. This is more.<\/p>\") xml_text(x) #> [1] \"This is some text. This is more.\" xml_text(x) <- \"This is some other text.\" xml_text(x) #> [1] \"This is some other text.text. This is more.\" # You can avoid this by explicitly selecting the text node. x <- read_xml(\"<p>This is some text. This is <b>bold!<\/b><\/p>\") text_only <- xml_find_all(x, \"//text()\") xml_text(text_only) <- c(\"This is some other text. \", \"Still bold!\") xml_text(x) #> [1] \"This is some other text. Still bold!\" xml_structure(x) #> <p> #> {text} #> <b> #> {text}"},{"path":"http://xml2.r-lib.org/dev/articles/modification.html","id":"attribute-and-namespace-definition-modification","dir":"Articles","previous_headings":"Modifying Existing XML","what":"Attribute and Namespace Definition Modification","title":"Node Modification","text":"Attributes namespace definitions modified one time xml_attr() xml_attrs(). cases using NULL value remove attribute completely.","code":"x <- read_xml(\"<a href='invalid!'>xml2<\/a>\") xml_attr(x, \"href\") #> [1] \"invalid!\" xml_attr(x, \"href\") <- \"https://github.com/r-lib/xml2\" xml_attr(x, \"href\") #> [1] \"https://github.com/r-lib/xml2\" xml_attrs(x) <- c(id = \"xml2\", href = \"https://github.com/r-lib/xml2\") xml_attrs(x) #> href id #> \"https://github.com/r-lib/xml2\" \"xml2\" x #> {xml_document} #> <a href=\"https://github.com/r-lib/xml2\" id=\"xml2\"> xml_attrs(x) <- NULL x #> {xml_document} #> <a> # Namespaces are added with as a xmlns or xmlns:prefix attribute xml_attr(x, \"xmlns\") <- \"http://foo\" x #> {xml_document} #> <a xmlns=\"http://foo\"> xml_attr(x, \"xmlns:bar\") <- \"http://bar\" x #> {xml_document} #> <a xmlns=\"http://foo\" xmlns:bar=\"http://bar\">"},{"path":"http://xml2.r-lib.org/dev/articles/modification.html","id":"name-modification","dir":"Articles","previous_headings":"Modifying Existing XML","what":"Name Modification","title":"Node Modification","text":"Node names modified xml_name().","code":"x <- read_xml(\"<a><b/><\/a>\") x #> {xml_document} #> <a> #> [1] <b/> xml_name(x) #> [1] \"a\" xml_name(x) <- \"c\" x #> {xml_document} #> <c> #> [1] <b/>"},{"path":"http://xml2.r-lib.org/dev/articles/modification.html","id":"node-modification","dir":"Articles","previous_headings":"","what":"Node modification","title":"Node Modification","text":"functions .copy argument. set FALSE remove new node location inserting new location. Otherwise make copy node insertion.","code":""},{"path":"http://xml2.r-lib.org/dev/articles/modification.html","id":"replacing-existing-nodes","dir":"Articles","previous_headings":"Node modification","what":"Replacing existing nodes","title":"Node Modification","text":"","code":"x <- read_xml(\"<parent><child>1<\/child><child>2<child>3<\/child><\/child><\/parent>\") children <- xml_children(x) t1 <- children[[1]] t2 <- children[[2]] t3 <- xml_children(children[[2]])[[1]] xml_replace(t1, t3) #> {xml_node} #> <child> x #> {xml_document} #> <parent> #> [1] <child>3<\/child> #> [2] <child>2<child>3<\/child><\/child>"},{"path":"http://xml2.r-lib.org/dev/articles/modification.html","id":"add-a-sibling","dir":"Articles","previous_headings":"Node modification","what":"Add a sibling","title":"Node Modification","text":"","code":"x <- read_xml(\"<parent><child>1<\/child><child>2<child>3<\/child><\/child><\/parent>\") children <- xml_children(x) t1 <- children[[1]] t2 <- children[[2]] t3 <- xml_children(children[[2]])[[1]] xml_add_sibling(t1, t3) x #> {xml_document} #> <parent> #> [1] <child>1<\/child> #> [2] <child>3<\/child> #> [3] <child>2<child>3<\/child><\/child> xml_add_sibling(t3, t1, where = \"before\") x #> {xml_document} #> <parent> #> [1] <child>1<\/child> #> [2] <child>3<\/child> #> [3] <child>2<child>3<\/child><child>1<\/child><\/child>"},{"path":"http://xml2.r-lib.org/dev/articles/modification.html","id":"add-a-child","dir":"Articles","previous_headings":"Node modification","what":"Add a child","title":"Node Modification","text":"","code":"x <- read_xml(\"<parent><child>1<\/child><child>2<child>3<\/child><\/child><\/parent>\") children <- xml_children(x) t1 <- children[[1]] t2 <- children[[2]] t3 <- xml_children(children[[2]])[[1]] xml_add_child(t1, t3) x #> {xml_document} #> <parent> #> [1] <child>1<child>3<\/child><\/child> #> [2] <child>2<child>3<\/child><\/child> xml_add_child(t1, read_xml(\"<test/>\")) x #> {xml_document} #> <parent> #> [1] <child>1<child>3<\/child><test/><\/child> #> [2] <child>2<child>3<\/child><\/child>"},{"path":"http://xml2.r-lib.org/dev/articles/modification.html","id":"removing-nodes","dir":"Articles","previous_headings":"Node modification","what":"Removing nodes","title":"Node Modification","text":"xml_remove() can used remove node (children) tree. default behavior unlink node tree, free memory node, R objects pointing node still valid. allows code like following work without crashing R planning referencing nodes memory wasted. Calling xml_remove(free = TRUE) remove nodes free memory used store . Note case node previously pointed node children instead pointing free memory may cause R crash. xml2 can’t figure , ’s responsibility remove objects longer valid. particular xml_find_*() results easy overlook, example","code":"x <- read_xml(\"<foo><bar><baz/><\/bar><\/foo>\") x1 <- x %>% xml_children() %>% .[[1]] x2 <- x1 %>% xml_children() %>% .[[1]] xml_remove(x1) rm(x1) gc() #> used (Mb) gc trigger (Mb) max used (Mb) #> Ncells 672183 35.9 1326505 70.9 1326505 70.9 #> Vcells 1167940 9.0 8388608 64.0 2566043 19.6 x2 #> {xml_node} #> <baz> x <- read_xml(\"<a><b /><b><b /><\/b><\/a>\") bees <- xml_find_all(x, \"//b\") xml_remove(xml_child(x), free = TRUE) # bees[[1]] is no longer valid!!! rm(bees) gc() #> used (Mb) gc trigger (Mb) max used (Mb) #> Ncells 672190 35.9 1326505 70.9 1326505 70.9 #> Vcells 1167938 9.0 8388608 64.0 2566043 19.6"},{"path":"http://xml2.r-lib.org/dev/articles/modification.html","id":"namespaces","dir":"Articles","previous_headings":"Node modification","what":"Namespaces","title":"Node Modification","text":"want construct document following namespace layout. (https://stackoverflow.com/questions/32939229/creating-xml--r--namespaces/32941524#32941524).","code":"<?xml version = \"1.0\" encoding=\"UTF-8\"?> <sld xmlns=\"http://www.opengis.net/sld\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:se=\"http://www.opengis.net/se\" version=\"1.1.0\" > <layer> <se:Name>My Layer<\/se:Name> <\/layer> <\/sld> d <- xml_new_root(\"sld\", \"xmlns\" = \"http://www.opengis.net/sld\", \"xmlns:ogc\" = \"http://www.opengis.net/ogc\", \"xmlns:se\" = \"http://www.opengis.net//se\", version = \"1.1.0\" ) %>% xml_add_child(\"layer\") %>% xml_add_child(\"se:Name\", \"My Layer\") %>% xml_root() d #> {xml_document} #> <sld version=\"1.1.0\" xmlns=\"http://www.opengis.net/sld\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:se=\"http://www.opengis.net//se\"> #> [1] <layer>\\n <se:Name>My Layer<\/se:Name>\\n<\/layer>"},{"path":"http://xml2.r-lib.org/dev/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Hadley Wickham. Author, maintainer. Jim Hester. Author. Jeroen Ooms. Author. . Copyright holder, funder. R Foundation. Contributor. Copy R-project homepage cached example","code":""},{"path":"http://xml2.r-lib.org/dev/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Wickham H, Hester J, Ooms J (2024). xml2: Parse XML. R package version 1.3.6.9000, https://github.com/r-lib/xml2, https://xml2.r-lib.org/.","code":"@Manual{, title = {xml2: Parse XML}, author = {Hadley Wickham and Jim Hester and Jeroen Ooms}, year = {2024}, note = {R package version 1.3.6.9000, https://github.com/r-lib/xml2}, url = {https://xml2.r-lib.org/}, }"},{"path":"http://xml2.r-lib.org/dev/index.html","id":"xml2","dir":"","previous_headings":"","what":"Parse XML","title":"Parse XML","text":"xml2 package binding libxml2, making easy work HTML XML R. API somewhat inspired jQuery.","code":""},{"path":"http://xml2.r-lib.org/dev/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Parse XML","text":"can install xml2 CRAN, can install development version github, using devtools:","code":"install.packages(\"xml2\") # install.packages(\"pak\") pak::pak(\"r-lib/xml2\")"},{"path":"http://xml2.r-lib.org/dev/index.html","id":"usage","dir":"","previous_headings":"","what":"Usage","title":"Parse XML","text":"three key classes: xml_node: single node document. xml_doc: complete document. Acting document usually acting root node document. xml_nodeset: set nodes within document. Operations xml_nodesets vectorised, apply operation node set.","code":"library(\"xml2\") x <- read_xml(\"<foo> <bar> text <baz/> <\/bar> <\/foo>\") x xml_name(x) xml_children(x) xml_text(x) xml_find_all(x, \".//baz\") h <- read_html(\"<html><p>Hi <b>!\") 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(\"<foo> a <b /><c><![CDATA[<d><\/d>]]><\/c><\/foo>\")) #> $foo #> $foo[[1]] #> [1] \" a \" #> #> $foo$b #> list() #> #> $foo$c #> $foo$c[[1]] #> [1] \"<d><\/d>\" #> #> #> as_list(read_xml(\"<foo> <bar><baz /><\/bar> <\/foo>\")) #> $foo #> $foo$bar #> $foo$bar$baz #> list() #> #> #> as_list(read_xml(\"<foo id = 'a'><\/foo>\")) #> $foo #> list() #> attr(,\"id\") #> [1] \"a\" #> as_list(read_xml(\"<foo><bar id='a'/><bar id='b'/><\/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} #> <x> # Nesting multiple nodes as_xml_document(list(foo = list(bar = list(baz = list())))) #> {xml_document} #> <foo> #> [1] <bar>\\n <baz/>\\n<\/bar> # attributes are stored as R attributes as_xml_document(list(foo = structure(list(), id = \"a\"))) #> {xml_document} #> <foo id=\"a\"> as_xml_document(list(foo = list( bar = structure(list(), id = \"a\"), bar = structure(list(), id = \"b\") ))) #> {xml_document} #> <foo> #> [1] <bar id=\"a\"/> #> [2] <bar id=\"b\"/>"},{"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><bar /><\/foo>\") #> {xml_document} #> <foo> #> [1] <bar/> read_html(\"<html><title>Hi<title><\/html>\") #> {html_document} #> <html> #> [1] <head>\\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset ... read_html(\"<html><title>Hi\") #> {html_document} #> <html> #> [1] <head>\\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset ... # From a local path read_html(system.file(\"extdata\", \"r-project.html\", package = \"xml2\")) #> {html_document} #> <html lang=\"en\"> #> [1] <head>\\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset ... #> [2] <body>\\n <div class=\"container page\">\\n <div class=\"row\">\\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(\"<p>Hi!<\/p>\") tmp <- tempfile(fileext = \".xml\") write_xml(h, tmp, options = \"format\") readLines(tmp) #> [1] \"<!DOCTYPE html PUBLIC \\\"-//W3C//DTD HTML 4.0 Transitional//EN\\\" \\\"http://www.w3.org/TR/REC-html40/loose.dtd\\\">\" #> [2] \"<html><body><p>Hi!<\/p><\/body><\/html>\" # write formatted HTML output write_html(h, tmp, options = \"format\") readLines(tmp) #> [1] \"<!DOCTYPE html PUBLIC \\\"-//W3C//DTD HTML 4.0 Transitional//EN\\\" \\\"http://www.w3.org/TR/REC-html40/loose.dtd\\\">\" #> [2] \"<html><body><p>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 id='1'><child id ='a' /><child id='b' d='b'/><\/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] <child id=\"a\"/> #> [2] <child id=\"b\" d=\"b\"/> 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 xmlns:b=\"http://bar.com\" xmlns:f=\"http://foo.com\"> <doc b:id=\"b\" f:id=\"f\" id=\"\" /> <\/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 <![CDATA[","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_cdata.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Construct a cdata node — xml_cdata","text":"","code":"x <- xml_new_root(\"root\") xml_add_child(x, xml_cdata(\"<d/>\")) as.character(x) #> [1] \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?>\\n<root><![CDATA[<d/>]]><\/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(\"<foo> <bar><boo /><\/bar> <baz/> <\/foo>\") xml_children(x) #> {xml_nodeset (2)} #> [1] <bar>\\n <boo/>\\n<\/bar> #> [2] <baz/> xml_children(xml_children(x)) #> {xml_nodeset (1)} #> [1] <boo/> xml_siblings(xml_children(x)[[1]]) #> {xml_nodeset (1)} #> [1] <baz/> # Note the each unique node only appears once in the output xml_parent(xml_children(x)) #> {xml_nodeset (1)} #> [1] <foo>\\n <bar>\\n <boo/>\\n <\/bar>\\n <baz/>\\n<\/foo> # Mixed content x <- read_xml(\"<foo> a <b/> c <d>e<\/d> f<\/foo>\") # Childen gets the elements, contents gets all node types xml_children(x) #> {xml_nodeset (2)} #> [1] <b/> #> [2] <d>e<\/d> xml_contents(x) #> {xml_nodeset (5)} #> [1] a #> [2] <b/> #> [3] c #> [4] <d>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} #> <b> xml_child(x, 2) #> {xml_node} #> <d> xml_child(x, \"baz\") #> {xml_missing} #> <NA>"},{"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] \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?>\\n<root>\\n <!--Hello!-->\\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( '<!DOCTYPE doc [ <!ELEMENT doc (#PCDATA)> <!ENTITY foo \" test \"> ]> <doc>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(\"<foo><bar><baz/><\/bar><baz/><\/foo>\") xml_find_all(x, \".//baz\") #> {xml_nodeset (2)} #> [1] <baz/> #> [2] <baz/> 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] <bar>\\n <baz/>\\n<\/bar> xml_find_all(bar, \".//baz\") #> {xml_nodeset (1)} #> [1] <baz/> xml_find_all(bar, \"//baz\") #> {xml_nodeset (2)} #> [1] <baz/> #> [2] <baz/> # Find all vs find one ----------------------------------------------------- x <- read_xml(\"<body> <p>Some <b>text<\/b>.<\/p> <p>Some <b>other<\/b> <b>text<\/b>.<\/p> <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] <b>text<\/b> #> [2] <b>other<\/b> #> [3] <b>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] <b>text<\/b> #> #> [[2]] #> {xml_nodeset (2)} #> [1] <b>other<\/b> #> [2] <b>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] <b>text<\/b> #> [2] <b>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(' <root xmlns:f = \"http://foo.com\" xmlns:g = \"http://bar.com\"> <f:doc><g:baz /><\/f:doc> <f:doc><g:baz /><\/f:doc> <\/root> ') xml_find_all(x, \".//f:doc\") #> {xml_nodeset (2)} #> [1] <f:doc>\\n <g:baz/>\\n<\/f:doc> #> [2] <f:doc>\\n <g:baz/>\\n<\/f:doc> xml_find_all(x, \".//f:doc\", xml_ns(x)) #> {xml_nodeset (2)} #> [1] <f:doc>\\n <g:baz/>\\n<\/f:doc> #> [2] <f:doc>\\n <g:baz/>\\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(\"<bar>123<\/bar>\") xml_name(x) #> [1] \"bar\" y <- read_xml(\"<bar><baz>1<\/baz>abc<foo /><\/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(' <root> <doc1 xmlns = \"http://foo.com\"><baz /><\/doc1> <doc2 xmlns = \"http://bar.com\"><baz /><\/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] <baz/> 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( \"<foo xmlns = 'http://foo.com'> <baz/> <bar xmlns = 'http://bar.com'> <baz/> <\/bar> <\/foo>\" ) # Need to specify the default namespaces to find the baz nodes xml_find_all(x, \"//d1:baz\") #> {xml_nodeset (1)} #> [1] <baz/> xml_find_all(x, \"//d2:baz\") #> {xml_nodeset (1)} #> [1] <baz/> # 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] <baz/> #> [2] <baz/>"},{"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(\"<foo><bar><baz /><\/bar><baz /><\/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(\"<a> <b><c>123<\/c><\/b> <b><c>456<\/c><\/b> <\/a>\") b <- xml_find_all(x, \"//b\") out <- xml_serialize(b, NULL) xml_unserialize(out) #> {xml_nodeset (2)} #> [1] <b>\\n <c>123<\/c>\\n<\/b> #> [2] <b>\\n <c>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(\"<a><b><c/><c/><\/b><d/><\/a>\")) #> <a> #> <b> #> <c> #> <c> #> <d> rproj <- read_html(system.file(\"extdata\", \"r-project.html\", package = \"xml2\")) xml_structure(rproj) #> <html [lang]> #> <head> #> <meta [charset]> #> <meta [http-equiv, content]> #> <meta [name, content]> #> <title> #> {text} #> <link [rel, type, href, sizes]> #> <link [rel, type, href, sizes]> #> {comment} #> <link [href, rel]> #> <link [href, rel]> #> {comment} #> {comment} #> {comment} #> <body> #> {text} #> <div [class]> #> {text} #> <div [class]> #> {text} #> <div [class, role]> #> {text} #> <div [class]> #> {text} #> <div [class]> #> {text} #> <p> #> <a [href]> #> <img [src, alt]> #> {text} #> <p> #> <small> #> <a [href]> #> {text} #> {text} #> <h2> #> {text} #> {text} #> <p> #> <a [href]> #> {text} #> {text} #> <h2> #> {text} #> {text} #> <ul> #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> {text} #> <div [class]> #> {text} #> <h2> #> {text} #> {text} #> <ul> #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> {text} #> <div [class]> #> {text} #> <h2> #> {text} #> {text} #> <ul> #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> {text} #> <div [class]> #> {text} #> <h2> #> {text} #> {text} #> <ul> #> <li> #> <a [href]> #> {text} #> {text} #> <li> #> <a [href]> #> {text} #> {text} #> {text} #> {text} #> {text} #> <div [class]> #> {text} #> <h1> #> {text} #> {text} #> <h2 [id]> #> {text} #> {text} #> <p> #> {text} #> <strong> #> <a [href]> #> {text} #> {text} #> <a [href]> #> {text} #> {text} #> {text} #> <p> #> {text} #> <a [href]> #> {text} #> {text} #> {text} #> <h2 [id]> #> {text} #> {text} #> <ul> #> <li> #> <p> #> <a [href]> #> <strong> #> {text} #> {text} #> {text} #> <li> #> <p> #> <strong> #> {text} #> {text} #> {text} #> <li> #> <p> #> <a [href]> #> <strong> #> {text} #> {text} #> {text} #> <li> #> <p> #> <strong> #> {text} #> {text} #> {text} #> <li> #> <p> #> <strong> #> <a [href]> #> {text} #> {text} #> {text} #> <li> #> <p> #> <strong> #> <a [href]> #> {text} #> {text} #> {text} #> {comment} #> {text} #> {text} #> <div [class]> #> {text} #> {text} #> {text} #> {comment} #> {text} #> <script [src]> #> {comment} #> <script [src]> xml_structure(xml_find_all(rproj, \".//p\")) #> [[1]] #> <p> #> <a [href]> #> <img [src, alt]> #> #> [[2]] #> <p> #> <small> #> <a [href]> #> {text} #> #> [[3]] #> <p> #> <a [href]> #> {text} #> #> [[4]] #> <p> #> {text} #> <strong> #> <a [href]> #> {text} #> {text} #> <a [href]> #> {text} #> {text} #> #> [[5]] #> <p> #> {text} #> <a [href]> #> {text} #> {text} #> #> [[6]] #> <p> #> <a [href]> #> <strong> #> {text} #> {text} #> #> [[7]] #> <p> #> <strong> #> {text} #> {text} #> #> [[8]] #> <p> #> <a [href]> #> <strong> #> {text} #> {text} #> #> [[9]] #> <p> #> <strong> #> {text} #> {text} #> #> [[10]] #> <p> #> <strong> #> <a [href]> #> {text} #> {text} #> #> [[11]] #> <p> #> <strong> #> <a [href]> #> {text} #> {text} #> h <- read_html(\"<body><p id = 'a'><\/p><p class = 'c d'><\/p><\/body>\") html_structure(h) #> <html> #> <body> #> <p#a> #> <p.c.d>"},{"path":"http://xml2.r-lib.org/dev/reference/xml_text.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract or modify the text — xml_text","title":"Extract or modify the text — xml_text","text":"xml_text returns character vector, xml_double returns numeric vector, xml_integer returns integer vector.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_text.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract or modify the text — xml_text","text":"","code":"xml_text(x, trim = FALSE) xml_text(x) <- value xml_set_text(x, value) xml_double(x) xml_integer(x)"},{"path":"http://xml2.r-lib.org/dev/reference/xml_text.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract or modify the text — xml_text","text":"x document, node, node set. trim TRUE trim leading trailing spaces. value character vector replacement text.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_text.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract or modify the text — xml_text","text":"character vector, length x.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_text.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract or modify the text — xml_text","text":"","code":"x <- read_xml(\"<p>This is some text. This is <b>bold!<\/b><\/p>\") xml_text(x) #> [1] \"This is some text. This is bold!\" xml_text(xml_children(x)) #> [1] \"bold!\" x <- read_xml(\"<x>This is some text. <x>This is some nested text.<\/x><\/x>\") xml_text(x) #> [1] \"This is some text. This is some nested text.\" xml_text(xml_find_all(x, \"//x\")) #> [1] \"This is some text. This is some nested text.\" #> [2] \"This is some nested text.\" x <- read_xml(\"<p> Some text <\/p>\") xml_text(x, trim = TRUE) #> [1] \"Some text\" # xml_double() and xml_integer() are useful for extracting numeric attributes x <- read_xml(\"<plot><point x='1' y='2' /><point x='2' y='1' /><\/plot>\") xml_integer(xml_find_all(x, \"//@x\")) #> [1] 1 2"},{"path":"http://xml2.r-lib.org/dev/reference/xml_type.html","id":null,"dir":"Reference","previous_headings":"","what":"Determine the type of a node. — xml_type","title":"Determine the type of a node. — xml_type","text":"Determine type node.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_type.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Determine the type of a node. — xml_type","text":"","code":"xml_type(x)"},{"path":"http://xml2.r-lib.org/dev/reference/xml_type.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Determine the type of a node. — xml_type","text":"x document, node, node set.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_type.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Determine the type of a node. — xml_type","text":"","code":"x <- read_xml(\"<foo> a <b /> <![CDATA[ blah]]><\/foo>\") xml_type(x) #> [1] \"element\" xml_type(xml_contents(x)) #> [1] \"text\" \"element\" \"text\" \"cdata\""},{"path":"http://xml2.r-lib.org/dev/reference/xml_url.html","id":null,"dir":"Reference","previous_headings":"","what":"The URL of an XML document — xml_url","title":"The URL of an XML document — xml_url","text":"useful interpreting relative urls url_relative().","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_url.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"The URL of an XML document — xml_url","text":"","code":"xml_url(x)"},{"path":"http://xml2.r-lib.org/dev/reference/xml_url.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"The URL of an XML document — xml_url","text":"x node document.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_url.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"The URL of an XML document — xml_url","text":"character vector length 1. Returns NA name set.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_url.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"The URL of an XML document — xml_url","text":"","code":"catalog <- read_xml(xml2_example(\"cd_catalog.xml\")) xml_url(catalog) #> [1] \"/home/runner/work/_temp/Library/xml2/extdata/cd_catalog.xml\" x <- read_xml(\"<foo/>\") xml_url(x) #> [1] NA"},{"path":"http://xml2.r-lib.org/dev/reference/xml_validate.html","id":null,"dir":"Reference","previous_headings":"","what":"Validate XML schema — xml_validate","title":"Validate XML schema — xml_validate","text":"Validate XML document XML 1.0 schema.","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_validate.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Validate XML schema — xml_validate","text":"","code":"xml_validate(x, schema)"},{"path":"http://xml2.r-lib.org/dev/reference/xml_validate.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Validate XML schema — xml_validate","text":"x document, node, node set. schema XML document containing schema","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_validate.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Validate XML schema — xml_validate","text":"TRUE FALSE","code":""},{"path":"http://xml2.r-lib.org/dev/reference/xml_validate.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Validate XML schema — xml_validate","text":"","code":"# Example from https://msdn.microsoft.com/en-us/library/ms256129(v=vs.110).aspx doc <- read_xml(system.file(\"extdata/order-doc.xml\", package = \"xml2\")) schema <- read_xml(system.file(\"extdata/order-schema.xml\", package = \"xml2\")) xml_validate(doc, schema) #> [1] TRUE #> attr(,\"errors\") #> character(0)"},{"path":[]},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-136","dir":"Changelog","previous_headings":"","what":"xml2 1.3.6","title":"xml2 1.3.6","text":"CRAN release: 2023-12-04 Now compatible libxml2 2.12.0 later (@KNnut). Fixed format string issues detected R-devel. Remove unused dependencies glue, withr lifecycle (@mgirlich). print() faster long xml_nodeset inputs (#366, @michaelchirico). xml_attr(), xml_attrs(), xml_double(), xml_integer(), xml_length(), xml_name(), xml_path(), xml_text(), xml_type() longer use S3 dispatch instead dispatch C, leading considerable performance improvements many cases (@mgirlich, #400). xml_find_int() analogous xml_find_num() returning integers matched XPath (#365, @michaelchirico). xml_serialize() now includes document type xml_unserialize() works also HTML documents (#407, @HenrikBengtsson).","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-135","dir":"Changelog","previous_headings":"","what":"xml2 1.3.5","title":"xml2 1.3.5","text":"CRAN release: 2023-07-06 Small speedup xml_find_all() (@mgirlich, #393). Fixes R CMD check problems.","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-134","dir":"Changelog","previous_headings":"","what":"xml2 1.3.4","title":"xml2 1.3.4","text":"CRAN release: 2023-04-27 Fixes R CMD check problems. Windows: update libxml2 2.10.3","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-133","dir":"Changelog","previous_headings":"","what":"xml2 1.3.3","title":"xml2 1.3.3","text":"CRAN release: 2021-11-30 Hadley Wickham now () maintainer. xml2 re-licensed MIT (#317). xml_find_all.xml_node() fails informatively xpath parameter wrong type (@michaelchirico) xml_find_all.xml_nodeset() gains flatten argument control whether return single nodeset list nodesets (#311, @jakejh) write_xml() write_html() now return NULL invisibly, prior version 1.3.0 (#307) XPtr gets explicit copy constructor assignment operator definitions, two missing components Rule three (@michaelchirico) Windows: update libxml2 2.9.10 libxslt 1.1.34 add ucrt libs","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-132","dir":"Changelog","previous_headings":"","what":"xml2 1.3.2","title":"xml2 1.3.2","text":"CRAN release: 2020-04-23 read_html() read_xml() now error passed strings length greater one (#121) read_xml.raw() inadvertent regression 1.3.0 now fixed (#300) Compilation fix macOS 10.15.4 (@kevinushey, #296)","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-131","dir":"Changelog","previous_headings":"","what":"xml2 1.3.1","title":"xml2 1.3.1","text":"CRAN release: 2020-04-09 read_html() now works HTML files non-ASCII encodings (#293).","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-130","dir":"Changelog","previous_headings":"","what":"xml2 1.3.0","title":"xml2 1.3.0","text":"CRAN release: 2020-04-01 Removes Rcpp dependency","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-125","dir":"Changelog","previous_headings":"","what":"xml2 1.2.5","title":"xml2 1.2.5","text":"CRAN release: 2020-03-11 Fix compilation issue macOS versions High Sierra using homebrew supplied libxml2","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-124","dir":"Changelog","previous_headings":"","what":"xml2 1.2.4","title":"xml2 1.2.4","text":"CRAN release: 2020-03-10 Fix potential dangling pointer internal asXmlChar() function (@michaelquinn32, #287). as_xml_document() now handles cases text nodes trailing normal nodes (#274). xml_add_child() can now create nodes par attribute. previously errored due partial name matching parent function internal create_node() function. (@jennybc, #285) libxml2_version() now returns semantic version rather alphanumeric version, “2.9.10” > “2.9.9” (#277)","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-122","dir":"Changelog","previous_headings":"","what":"xml2 1.2.2","title":"xml2 1.2.2","text":"CRAN release: 2019-08-09 Export S4 classes documentation, can used packages without Warnings (@nuest, #267)","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-121","dir":"Changelog","previous_headings":"","what":"xml2 1.2.1","title":"xml2 1.2.1","text":"CRAN release: 2019-07-29","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"new-features-1-2-1","dir":"Changelog","previous_headings":"","what":"New Features","title":"xml2 1.2.1","text":"xml2 now pkgdown site! https://xml2.r-lib.org (@jayhesselberth, #211). Windows: upgrade libxml2 2.9.8 print methods now match type document, e.g. read_html() prints “{html_document}” rather “{xml_document}” (#227)","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"bugfixes-and-miscellaneous-features-1-2-1","dir":"Changelog","previous_headings":"","what":"Bugfixes and Miscellaneous features","title":"xml2 1.2.1","text":"Generic xml2 error now forwarded R errors. Previously errors output stderr, suppressed (#209). Fix ICU 59+ defaulting use char16_t, available C++11 (#231) longer uses C connections API Better error message trying run download_xml() without curl package installed (#262) xml2 classes now registered use S4 calling setOldClass() (#248) Nodes nested data type definition entities now work without crashing (#241) Test failure fixed due behavior change relative paths libxml2 2.9.9 (#245). read_xml() now better error message given zero length character inputs (#212). read_xml() read_html() now automatically check response succeeded trying read HTTP response (#255). xml_root() can now create root nodes namespaces (#239) xml_set_attr() longer crashes try set namespace node multiple times (#253). xml_set_attr() now recycles values needed (#221) xml_structure() gains file argument, support writing file rather console (#244).","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-120","dir":"Changelog","previous_headings":"","what":"xml2 1.2.0","title":"xml2 1.2.0","text":"CRAN release: 2018-01-24","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"breaking-changes-1-2-0","dir":"Changelog","previous_headings":"","what":"Breaking changes","title":"xml2 1.2.0","text":"as_list() xml_document objects properly include root node returned list. Previous behavior can obtained using as_list()[[1L]] place as_list().","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"new-features-1-2-0","dir":"Changelog","previous_headings":"","what":"New Features","title":"xml2 1.2.0","text":"download_xml() download_html() helper functions make easy download files (#193). xml_attr() can now set attributes value (#198). xml_serialize() xml_unserialize() now create file connections given character input (#179).","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"bugfixes-1-2-0","dir":"Changelog","previous_headings":"","what":"Bugfixes","title":"xml2 1.2.0","text":"xml_find_first() longer de-duplicates results, results always length inputs (documented) (#194). xml2 can now build using libxml2 2.7.0 Use Rcpp symbol registration visibility prevent symbol conflicts Linux xml_add_child() now requires less resources insert node called .= 0L (@heckendorfc, #175). Fixed failing examples due change external resource.","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-111","dir":"Changelog","previous_headings":"","what":"xml2 1.1.1","title":"xml2 1.1.1","text":"CRAN release: 2017-01-24 small point release addressing installation issues found older libxml2 versions shipped RedHat Linux 6 / CentOS 6 (#163, #164).","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-110","dir":"Changelog","previous_headings":"","what":"xml2 1.1.0","title":"xml2 1.1.0","text":"CRAN release: 2017-01-07","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"new-features-1-1-0","dir":"Changelog","previous_headings":"","what":"New Features","title":"xml2 1.1.0","text":"write_xml() write_html() now accept connections well filenames output. (#157) xml_add_child() now takes .argument specifying add new children. (#138) as_xml() generic function convert R objects xml. important method lists enables full roundtrip support going back xml lists enables full roundtrip support XML. (#137, #143) xml_new_root() can used create new document root node one step (#131). xml_add_parent() inserts new node node parent (#129) Add xml_validate() validate document xml schema (#31, @jeroenooms). Export xml2_types.h allow extension packages xslt. xml_comment() allows add comment nodes document. (#111) xml_cdata() allows add CDATA nodes document. (#128) Add xml_set_text() xml_set_name() equivalent xml_text<- xml_name<-. (#130). Add xml_set_attr() xml_set_attrs() equivalent xml_attr<- xml_attrs<-. (#109, #130) Add write_html() method (#133).","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"bugfixes-1-1-0","dir":"Changelog","previous_headings":"","what":"Bugfixes","title":"xml2 1.1.0","text":"xml_new_document() now explicitly sets encoding (default UTF-8) (#142) Document formatting options write_xml() (#132) Add missing methods xml_missing objects. (#134) Bugfix xml_length.xml_nodeset caused fail unconditionally. (#140) .na() now returns TRUE xml_missing objects. (#139) Trim non-breaking spaces xml_text(trim = TRUE) (#151). Allow setting non-character attributes (values coerced characters). (@sjp, #117, #122). Fixed return value call vapply xml_integer.xml_nodeset. (@ddiez, #146, #147). Allow docs missing root element created printed. (@sjp, #126, #121). xml_add_* methods now return invisibly. (@sjp, #124) as_list() now preserves element names attributes exist, escapes XML attributes conflict special R attributes (@peterfoley, #115).","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-100","dir":"Changelog","previous_headings":"","what":"xml2 1.0.0","title":"xml2 1.0.0","text":"CRAN release: 2016-06-24 C++ functions now use checked_get() instead get() possible, NULL XPtrs properly throw error rather crashing. (@jimhester, #101, #104). xml_integer() xml_double() functions make easy extract integer double text nodes (@jimhester, #97, #99). xml2 now supports modification creation XML nodes. New functions xml_new_document(), xml_new_child(), xml_new_sibling(), xml_set_namespace(), , xml_remove(), xml_replace(), xml_root() replacement methods xml_name(), xml_attr(), xml_attrs() xml_text() (@jimhester, #9 #76) xml_ns() now keeps namespace prefixes point URI (@jimhester, #35, #95). read_xml() read_html() methods added httr::response() objects. (@jimhester, #63, #93) xml_child() function make selecting children little easier (@jimhester, #23, #94) xml_find_one() deprecated favor xml_find_first() (@jimhester, #58, #92) xml_read() functions now default passing document’s namespace object. Namespace definitions can now removed well added xml_ns_strip() added remove default namespaces document. (@jimhester, #28, #89) xml_read() gains options argument control available parsing options, including HUGE turn limits parsing large documents now drops blank text nodes default, mimicking default behavior XML package. (@jimhester, #49, #62, #85, #88) xml_write() expands path filenames, directories can specified ‘~/’ (@jimhester, #86, #80) xml_find_one() now returns ‘xml_missing’ node object 0 matches (@jimhester, #55, #53, hadley/rvest#82). xml_find_num(), xml_find_chr(), xml_find_lgl() functions added return numeric, character logical results XPath expressions. (@jimhester, #55) xml_name() xml_text() always correctly encode returned value UTF-8 (#54).","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-012","dir":"Changelog","previous_headings":"","what":"xml2 0.1.2","title":"xml2 0.1.2","text":"CRAN release: 2015-09-01 Improved configure script - now works R-devel windows. Compiles older versions libxml2.,","code":""},{"path":"http://xml2.r-lib.org/dev/news/index.html","id":"xml2-011","dir":"Changelog","previous_headings":"","what":"xml2 0.1.1","title":"xml2 0.1.1","text":"CRAN release: 2015-06-02 Make configure script cross platform. Add xml_length() count number children (#32).","code":""}]