Process Stanford departments XML data into a data frame
Source:R/process.R
process_departments_xml.RdParses XML data containing Stanford University department information into a structured data frame. The function processes hierarchical XML data where departments are nested within schools, extracting department codes, full names, and their associated schools.
Value
A tibble with three columns:
name: Character. Department code/abbreviation (e.g., "CS")longname: Character. Full department name (e.g., "Computer Science")school: Character. Name of the school containing the department
Details
The function performs the following steps:
Locates all school nodes in the XML using XPath
For each school, extracts its name and finds all department nodes
For each department, extracts:
Department code (
name)Full department name (
longname)Associated school name (
school)
Combines all departments into a single data frame
The function includes error handling for:
Missing school data
Missing department data
XML parsing errors
See also
xml2::xml_find_all()for the XML parsing functionalityfetch_departments()for the public interface to this functionality
Examples
if (FALSE) { # \dontrun{
xml_data <- xml2::read_xml("departments.xml")
departments_df <- process_departments_xml(xml_data)
} # }