[英]Parsing XML into an R data frame
我試圖將一個大的xml文件解析為R - data.frame對象。 xml具有以下架構:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?eclipse version="3.0"?>
<ROOT>
<row>
<field name="dtcreated"></field>
<field name="headline"></field>
<subheadline/>
<field name="body"></field>
</row>
<row>
<field name="dtcreated"></field>
<field name="headline"></field>
<subheadline/>
<field name="body"></field>
</row>
</ROOT>
plyr便利功能沒有幫助,因為無法驗證xml。 所以我想出了以下代碼,使用xpath查詢:
adHocXml<-xmlTreeParse(adHocXmlPath,getDTD = FALSE)
adHocRoot<-xmlRoot(adHocXml)
creationDateColumn<-sapply(getNodeSet(adHocRoot,"//row//field[@name='dtcreated']"), xmlValue)
headlineColumn<-sapply(getNodeSet(adHocRoot,"//row//field[@name='headline']"), xmlValue)
bodyColumn<-sapply(getNodeSet(adHocRoot,"//row//field[@name='body']"), xmlValue)
adHocData<-data.frame(creationDate=creationDateColumn,headline=headlineColumn,body=bodyColumn)
代碼完全符合我期望它為短文件做的事情。 但是,使用大文件和幾千行標簽,大約10分鍾后會出現以下錯誤:
Error: 1: internal error: Huge input lookup
2: Extra content at the end of the document
誰能幫我?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.