我正在尝试将 xml 文件转换为数据框,而对于某些元素它运行良好,而对于其他元素则不是。我不确定为什么。
这是 XML 的简单版本:
<?xml version="1.0" encoding="UTF-8"?>
<clinical_study rank="6838">
<arm_group>
<arm_group_label>Arm I (Lozenge placebo)</arm_group_label>
<arm_group_type>Placebo Comparator</arm_group_type>
<description>Patients receive lozenge placebo PO QID.</description>
</arm_group>
<arm_group>
<arm_group_label>Arm II (LBR lozenge)</arm_group_label>
<arm_group_type>Experimental</arm_group_type>
<description>Patients receive lyophilized black raspberries lozenge PO (8gms/day)</description>
</arm_group>
<arm_group>
<arm_group_label>Arm III (Saliva Substitute placebo)</arm_group_label>
<arm_group_type>Placebo Comparator</arm_group_type>
<description>Patients receive Saliva Substitute placebo PO QID.</description>
</arm_group>
<arm_group>
<arm_group_label>Arm IV (LBR Saliva Substitute)</arm_group_label>
<arm_group_type>Experimental</arm_group_type>
<description>Patients receive lyophilized black raspberries Saliva Substitute PO (8gms/day).</description>
</arm_group>
<condition_browse>
<!-- CAUTION: The following MeSH terms are assigned with an imperfect algorithm -->
<mesh_term>Carcinoma</mesh_term>
<mesh_term>Carcinoma, Squamous Cell</mesh_term>
<mesh_term>Laryngeal Diseases</mesh_term>
<mesh_term>Laryngeal Neoplasms</mesh_term>
<mesh_term>Oropharyngeal Neoplasms</mesh_term>
<mesh_term>Carcinoma, Verrucous</mesh_term>
<mesh_term>Nasopharyngeal Neoplasms</mesh_term>
<mesh_term>Salivary Gland Neoplasms</mesh_term>
<mesh_term>Paranasal Sinus Neoplasms</mesh_term>
<mesh_term>Head and Neck Neoplasms</mesh_term>
<mesh_term>Neoplasms, Unknown Primary</mesh_term>
<mesh_term>Mouth Neoplasms</mesh_term>
<mesh_term>Hypopharyngeal Neoplasms</mesh_term>
<mesh_term>Tongue Neoplasms</mesh_term>
<mesh_term>Lip Neoplasms</mesh_term>
<mesh_term>Carcinoma in Situ</mesh_term>
</condition_browse>
<!-- Results have not yet been posted for this study -->
</clinical_study>
我正在使用的代码(工作一个):
library(XML)
library(dplyr)
library(xml2)
# read group
outc <- xml_find_all(xml, "//arm_group") %>% as_list() %>% dplyr::bind_rows() %>% as.data.frame()
并且这段代码不起作用:
test1 <- xml_find_all(xml, "//condition_browse") %>% as_list() %>% dplyr::bind_rows() %>% as.data.frame()
第二段代码生成一个只有 1 行的数据集,而不是预期的多行数据帧。
我无法确定错误是来自我的 xml2 语法、xpath 一还是仅仅来自 xml 数据。
可以请支持吗?