Type: | Package |
Title: | XML Generation from Tables |
Version: | 1.1.0 |
Description: | Converting structured data from tables into XML format using predefined templates ensures consistency and flexibility, making it ideal for data exchange, reporting, and automated workflows. |
License: | MIT + file LICENSE |
URL: | https://josesamos.github.io/tab2xml/, https://github.com/josesamos/tab2xml |
BugReports: | https://github.com/josesamos/tab2xml/issues |
Imports: | readODS, readxl, stringr, tools |
Suggests: | knitr, rmarkdown, testthat (≥ 3.0.0), xml2 |
VignetteBuilder: | knitr |
Config/testthat/edition: | 3 |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
NeedsCompilation: | no |
Packaged: | 2025-04-01 18:18:22 UTC; jsamos |
Author: | Jose Samos |
Maintainer: | Jose Samos <jsamos@ugr.es> |
Repository: | CRAN |
Date/Publication: | 2025-04-01 18:30:02 UTC |
Validate and Check Spreadsheet Data
Description
This function validates the structure of a spreadsheet file by checking its sheets, primary keys (PKs), and foreign keys (FKs). If a template file is provided, it also checks the column definitions.
Usage
check_tab(file_path, template_path = NULL)
Arguments
file_path |
Character. Path to the spreadsheet file to be validated. |
template_path |
Character (optional). Path to the template file for validation. If 'NULL', only the sheet structure is checked. |
Value
Logical. Returns "TRUE" but warns of possible errors.
Check if a dataframe cell is empty
Description
This function checks whether a given cell from a dataframe is empty. A cell is considered empty if it contains 'NA' or an empty string ('""').
Usage
is_cell_empty(cell)
Arguments
cell |
A single value from a dataframe. |
Value
'TRUE' if the cell is empty ('NA' or '""'), otherwise 'FALSE'.
Remove Empty XML Nodes Recursively
Description
This function traverses an XML node and removes any empty child nodes. A node is considered empty if it has no children, no text content, and no attributes.
Usage
remove_empty_nodes(node)
Arguments
node |
An XML node of class 'xml_node' from the 'xml2' package. |
Value
The function modifies the XML structure in place and does not return a value.
Convert a Spreadsheet to XML
Description
It reads a spreadsheet file (Excel or ODS), processes it using a provided XML template, and generates an XML output file.
Usage
sheet2xml(file_path, template_path, xml_path = NULL, optimize = FALSE)
Arguments
file_path |
Character. Path to the spreadsheet file to be converted. Supports Excel (.xlsx) and ODS formats. |
template_path |
Character. Path to the XML template file to guide the transformation process. |
xml_path |
Character (optional). Output path for the generated XML file. If NULL, it is considered an XML file with the same name and location as the spreadsheet file. |
optimize |
Boolean. Remove empty nodes from the xml file. |
Value
Character. The file path of the generated XML document.
Examples
source_xml <- system.file("extdata", "schema_template.xml", package = "tab2xml")
source_xlsx <- system.file("extdata", "schema.xlsx", package = "tab2xml")
temp_file1 <- tempfile(fileext = ".xml")
sheet2xml(source_xlsx, source_xml, temp_file1)
source_ods <- system.file("extdata", "schema.ods", package = "tab2xml")
temp_file2 <- tempfile(fileext = ".xml")
sheet2xml(source_ods, source_xml, temp_file2)
Validate foreign key column
Description
Checks if a foreign key column exists in the reference table and ensures make all values in the foreign key column match the existing values in the primary key column of the referenced table.
Usage
validate_fk(table_pk, name_pk, table_fk, name_fk)
Arguments
table_pk |
A data frame that represents the table containing the primary key. |
name_pk |
A string indicating the name of the table to which reference. |
table_fk |
A data frame that represents the table containing the foreign key. |
name_fk |
A character string indicating the name of the reference table. |
Value
'TRUE'. Generates warnings if the foreign key column is missing from the reference table or if it contains values that are not present in the column primary key of the referenced table.
Validate primary key column
Description
Checks if a table contains a correctly formatted primary key column. Primary key column must exist, no missing values and contain unique values.
Usage
validate_pk(table, name)
Arguments
table |
A data frame that represents the table to validate. |
name |
A string indicating the name of the table. |
Value
'TRUE'. Generates warnings if primary key column is missing or has duplicates.