Parse XML

Bindings to 'libxml2' for working with XML data using a simple, consistent interface based on 'XPath' expressions. Also supports XML schema validation; for 'XSLT' transformations see the 'xslt' package.


xml2

CRAN_Status_Badge Codecov testcoverage R buildstatus R-CMD-check

The xml2 package is a binding to libxml2, making it easy to work with HTML and XML from R. The API is somewhat inspired by jQuery.

Installation

You can install xml2 from CRAN,

install.packages("xml2")

or you can install the development version from github, using pak:

# install.packages("pak")
pak::pak("r-lib/xml2")

Usage

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)

There are three key classes:

  • xml_node: a single node in a document.

  • xml_doc: the complete document. Acting on a document is usually the same as acting on the root node of the document.

  • xml_nodeset: a set of nodes within the document. Operations on xml_nodesets are vectorised, apply the operation over each node in the set.

Compared to the XML package

xml2 has similar goals to the XML package. The main differences are:

  • xml2 takes care of memory management for you. It will automatically free the memory used by an XML document as soon as the last reference to it goes away.

  • xml2 has a very simple class hierarchy so you don’t need to think about exactly what type of object you have, xml2 will just do the right thing.

  • More convenient handling of namespaces in Xpath expressions - see xml_ns() and xml_ns_strip() to get started.

Code of Conduct

Please note that the xml2 project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("xml2")

1.6.0 by Jeroen Ooms, 4 months ago


https://xml2.r-lib.org, https://r-lib.r-universe.dev/xml2


Report a bug at https://github.com/r-lib/xml2/issues


Browse source code at https://github.com/cran/xml2


Authors: Hadley Wickham [aut] , Jim Hester [aut] , Jeroen Ooms [aut, cre] , Posit Software , PBC [cph, fnd] , R Foundation [ctb] (Copy of R-project homepage cached as example)


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports cli, methods, rlang

Suggests covr, curl, httr, knitr, mockery, rmarkdown, testthat, xslt

System requirements: libxml2: libxml2-dev (deb), libxml2-devel (rpm)


Imported by AnnoProbe, Argentum, AzureStor, BAwiR, BFS, BIS, BOJ, CLDedgelister, CatastRo, Certara.NLME8, Certara.R, Certara.RsNLME, CopernicusDataspace, CopernicusMarine, DDIwR, DEPONS2R, DEXiR, DIZutils, EDIutils, EGM, EML, Ecfun, EdSurvey, FAIRmaterials, FSK2R, FedData, GTFShift, GetBCBData, GetDFPData2, GetFREData, GetLattesData, GetTDData, HCUPtools, ICESat2VegR, IDSL.MXP, IFC, KLINK, LAGOSNE, LBDiscover, LLMAgentR, LMPdata, LitFetchR, MSbox, MatchingPursuit, MazamaCoreUtils, MediaNews, NHSDataDictionaRy, NLPclient, OAIHarvester, OECD, OralOpioids, PAMmisc, PAMpal, PFW, PKbioanalysis, PRISMA2020, PTXQC, ParallelLogger, PubMatrixR, RAGFlowChainR, RBNZ, RDML, RISmed, RKorAPClient, RNeXML, ROI.plugin.neos, RaMS, RefManageR, Rigma, Rveg, SMMT, SNPannotator, SP2000, SanFranBeachWater, SchoolDataIT, SticsRFiles, SubtypeDrug, SwimmeR, TKCat, TheOpenAIR, UKBAnalytica, UKFE, WordR, act, activatr, addinslist, adjustedcranlogs, aire.zmvm, amapGeocode, angstromATE, aphylo, apsimx, archiveRetriever, avidaR, aws.ecx, aws.iam, aws.s3, babette, bacenR, banxicoR, bbk, bcdata, bcmaps, beastier, bibliometrix, binman, bioRad, biolink, bluertopo, bodsr, box.linters, bpmnVisualizationR, breathtestcore, btw, bunddev, camsRad, checktor, chromConverter, cifti, ciftiTools, clc, cliapp, climaemet, clinDataReview, clintools, cms, coalitions, codemetar, convertid, covidcast, cppcheckR, crawlee, crew.cluster, cricketdata, ctrlvee, d4storagehub4R, daiR, danlex, dataRetrieval, datamedios, datasus, dataverse, defineR, delma, denguedatahub, dexisensitivity, diagFDR, distill, docket, docorator, docxtractr, eCerto, easyRef, easyScieloPack, easybio, ecb, ecocomDP, eddington, edgarWebR, elcf4R, emayili, emld, epidata, epidatr, epitab, epubr, equatags, essurvey, etl, eudract, eurlex, eurodata, europepmc, eurostat, exams.forge, exams.mylearn, exams2sakai, export, faersquarterlydata, fastqcr, faviconPlease, fedstatAPIr, ffiec, ffm, fhircrackr, finch, finlex, finna, fitzRoy, fixr, flatxml, flextable, foghorn, foqat, forensicpopdata, freesurferformats, frheritage, galah, gasanalyzer, gcite, gdalraster, geneExpressionFromGEO, geneNR, geniusr, geofi, geoflow, geosapi, getLattes, getRad, gfer, gganime, ggsem, gifti, gleifr, glossary, gridmicrotex, gridtext, gt, gto, handlr, happign, helsinki, heumilkr, huxtable, hydrogeofetch, icesSAG, icons, ihpdr, immunogenetr, incidentally, ineptr2, insect, insee, investdatar, ipumsr, istatR, jentre, jmastats, jstager, juicedown, junco, kableExtra, kanjistat, knitxl, krt, languageserver, letsHerp, letsRept, libbib, lightr, limonaid, link, lintr, logolink, lssdoc, mRpostman, macleish, maidr, malariaAtlas, mapsapi, marcxmlr, matchpointR, mclm, meta, metacore, metainsight, meteospain, midas, modisfast, monashtipr, moodef, mortSOA, move, mpaR, mregions2, mschart, mums2, munch, musicXML, ncaavolleyballr, neurohcp, newsanchor, ngramr, nhanesA, nhdR, nhdplusTools, nhlscraper, nonmem2rx, nonmemica, nrlR, nser, nzffdr, nzilbb.labbcat, oRaklE, oai, officedown, officer, omsvg, openSkies, opendataformat, opendatatoronto, openrouteservice, osmapiR, osmdata, ottrpal, owidR, pacs, pangaear, parcxl, partycoloR, pastclim, patentr, paws.common, pdfetch, pkgdown, pmparser, pmxTools, polish, polmineR, porter, postdoc, postlightmercury, potentiomap, prismjs, pubmedtk, pulso, puremoe, pzfx, qtkit, quanteda, rAmCharts4, rPDBapi, rPanglaoDB, rStrava, ragnar, ralger, rbcb, rcatfish, rcrossref, rdav, rddi, rdhs, rdnb, rdomains, rdracor, readabs, readapra, readelan, readmoRe, readrba, readsdr, readtext, realestatebr, refdb, relSim, reptiledbr, reqres, rerddap, respR, restatapi, retraction, retrosheet, revise, rfacts, rfair, rfishbase, rgbif, rgrass, risk.assessr, riskmetric, rnpn, robis, rorcid, roxygen2, rqti, rrstools, rsei, rsides, rspacer, rstudiothemes, rsurvstat, rtransparency, rtrek, rvest, rvg, ryandexdirect, salesforcer, sarp.snowprofile, sarsop, scaper, scholar, scilintr, scorecard, scraEP, scrappy, sdbuildR, searchlight, secfile, sejmRP, senatebR, sgapi, shinyloadtest, simDNAmixtures, sjtable2df, socialmixr, solrium, solvency2rfr, sorvi, spanish, spanishoddata, sparklyr, speaq, speechbr, spelling, spiritR, spiro, spotifyr, srppp, sss, statnipokladna, stemmatology, sumer, surveydown, svgedit, svgtools, swatches, tabular, taxize, teal.widgets, telegramR, templr, texPreview, textpress, thredds, threeBrain, tidyRSS, tidycensus, tidygeoRSS, tidytuesdayR, tidyverse, tinkr, tinyscholar, tm, tm.plugin.factiva, tm.plugin.lexisnexis, toolero, trackeR, trainR, traits, treasury, twbparser, unexcel, unicefData, unpivotr, urlchecker, usedthese, vdiffr, vegdata, vennDiagramLab, vvtableau, wdpar, weatherOz, webchem, webdav, wikifacts, wikilake, wikitaxa, worldfootballR, wosr, x3ptools, xesreadR, xml2relational, xmlconvert, xmlrectr, xmlrpc2, zen4R.

Depended on by FFdownload, hyperSpec, interlineaR, xslt.

Suggested by AMR, AddiVortes, Athlytics, BeeBDC, CLVTools, CorrectOverloadedPeaks, DBI, DOPE, DrugUtilisation, EmiR, Families, LexisNexisTools, MDP2, NBAloveR, OpenML, RMixtComp, RMixtCompIO, RMixtCompUtilities, RSQLite, RcppAlgos, RprobitB, SIAtools, STATcubeR, SpaDES.core, SpatialKDE, StreamCatTools, VirtualPop, anybadger, ape, applicable, arcpullr, artoo, avesperu, baseballr, batchmix, bdc, blastula, blockr.dock, blockr.session, blueterra, bookdown, bscui, camtrapdp, cancensus, cardargus, caretEnsemble, ckanr, clinify, cloudfs, clustur, cmsaf, cmstatrExt, commonmark, controlcharts, coreval, covr, crosstable, csquares, ct, ctv, dataone, dataquieR, denim, devtools, dials, discrim, downlit, dplyneage, easystats, ecmwfr, ecochange, effectcheck, ernest, exams, fImport, familiar, fastRhockey, fastcpd, finalsize, fireproof, galaxias, geomtextpath, ggiraph, ggnext, ggplot2, gluedown, googleLanguageR, gtExtras, gutenbergr, highlightr, hoopR, htmlTable, httpgd, httptest, httptest2, httr, httr2, hydrodownloadR, iai, ieegio, inTextSummaryTable, isoband, kamila, landmaRk, lifecycle, lobsteR, logrx, manynet, markovchain, metasurvey, mlr3oml, mmrm, morseTKTD, move2, mrgsolve, mscstts, mutator, naaccr, neonstore, nethist, neuroim2, ngme2, nocturn, nuggets, oddsapiR, odiffr, oeli, orderanalyzer, osmnxr, pagedown, pense, phsopendata, pins, pkgnews, plasmidplot, protti, prt, psborrow2, pxweb, qatarcars, qdaR, quantmod, queryup, r2rtf, r311, rar, rasch, rayrender, rchime, rco, rdflib, readr, recipes, repurrrsive, revealjs, ricu, rio, rmarkdown, roxyreqs, rsample, rscopus, rtables, rtables.officer, rtemis.llm, rtestim, runexp, samplr, sbtools, searchAnalyzeR, seine, selectr, selenider, selenium, sharpshootR, shinyMonacoEditor, shinyOAuth, shinyscholar, smer, smidm, smoothemplik, soilDB, specProc, sprtt, strollur, svglite, tab2xml, tarchetypes, taxodist, testthat, texanshootR, text, textclassificationtutorial, tidyEmoji, tidymodels, torchvision, tuber, tubern, tufte, tune, ume, unigd, units, vcfheader, vctrs, vosonSML, vroom, waldo, webfakes, webmockr, wehoop, writexl, xfun, xmlparsedata, xmlwriter, xutils.

Enhanced by svgPanZoom.


See at CRAN