【发布时间】:2017-09-22 11:05:55
【问题描述】:
我有一些 XML 数据如下:
<?xml version=1.0 encoding=UTF-8?>
<tasks xml=xyz.com/abc/wkbh/task>
<task>
<taskxml>
<Claim prDocumentIdentifier=137####_##62###>
<ClaimNumber>13####_##62###</ClaimNumber>
<FreeTextDescription>INS PASSENGER IN UNINSURED AUTOMOBILE THAT VEERED OFF THE RD INTO A DITCH</FreeTextDescription>
<ClaimCauses>
<ClaimCause>
<ActualValue>THIRD PARTY STRUCK INSURED'S PARKED VEHICLE</ActualValue>
<Category>MOTOR_ACCIDENT_TP_HIT_FP</Category>
</ClaimCause>
</ClaimCauses>
<IncidentDate>2006-10-13</IncidentDate>
<IncidentTime>14:30:00.000</IncidentTime>
<ReportedDate>2008-01-28</ReportedDate>
<ReportedTime>13:14:00.000</ReportedTime>
<ClosureDate>2014-06-25</ClosureDate>
<PolicyHolderDrivingAnotherVehicleFlag>N</PolicyHolderDrivingAnotherVehicleFlag>
<UnusualCircumstancesFlag>N</UnusualCircumstancesFlag>
<LiableParties>
<ActualValue>DRIVER NOT AT FAULT</ActualValue>
</LiableParties>
<ClaimType>
<Category>PERSONAL_MOTOR</Category>
</ClaimType>
<ClaimStatus>
<ActualValue>OPEN</ActualValue>
<Category>OPEN</Category>
</ClaimStatus>
<CloseReason>
<ActualValue>PAID</ActualValue>
<Category>SETTLED</Category>
</CloseReason>
<ClaimReportedBy>
<ActualValue>OTHER</ActualValue>
</ClaimReportedBy>
<SupportingInformation>
<AuthoritiesNotifiedOrAtScene>N</AuthoritiesNotifiedOrAtScene>
<UnusualCircumstances>N</UnusualCircumstances>
</SupportingInformation>
<ClaimSites>
<ClaimSite>
<IsOccupiedFlag>Y</IsOccupiedFlag>
</ClaimSite>
</ClaimSites>
<MotorClaimVehicles>
<MotorClaimVehicle>
<ID>104####_137####</ID>
<MotorClaimVehicleRole>
<ActualValue>POLICY_HOLDER_VEHICLE</ActualValue>
<Category>POLICY_HOLDER_VEHICLE</Category>
</MotorClaimVehicleRole>
<Make>FORD</Make>
<ManufactureYear>2002</ManufactureYear>
<Model>FOCUS SE WAGON</Model>
<Status>
<Category>ACTIVE</Category>
</Status>
<TotalDistanceTravelled>
<Units>KM</Units>
<Amount>0</Amount>
</TotalDistanceTravelled>
<OwnershipStatus>
<ActualValue>OWNED</ActualValue>
<Category>OWNED</Category>
</OwnershipStatus>
</MotorClaimVehicle>
</MotorClaimVehicles>
</Claim>
</taskxml>
</task>
</tasks>
我正在尝试将 ClaimNumber、FreeTextDescription 等列提取到数据框中。当我尝试使用 XML 包解析数据时
xml_df_task <- xmlParse("xyz.xml")
我收到以下错误:
Error: 1: String not started expecting ' or "
2: Malformed declaration expecting version
3: Blank needed here
4: parsing XML declaration: '?>' expected
5: AttValue: " or ' expected
6: attributes construct error
7: Couldn't find end of Start Tag tasks line 1
8: Extra content at the end of the document
我是 XML 相关包的新手。因此,非常感谢有关此错误的任何帮助。
附:这只是实际列的一个小sn-p。
编辑: XML 是有效的,但它嵌入在文本格式的数据的某些列中。当我尝试读取 R 中的文本数据并使用代码转换为数据框时:
fpath <- "pathofdata.txt"
dat <- read.table(fpath, header = T, sep = "|", fill = T)
我得到了一个数据框,但由于一些引号消失了,XML 内容变得无效。因此,尝试在数据框步骤之后将其解析为单独的 XML 是行不通的。
更新的数据sn-p:
H|TASK_ID|TASK_REFERENCE|TASK_NAME|TASK_TYPE|TASK_RAISED_TS|TASK_STATE|TASK_VIEWED_FLAG|TASK_OUTCOME|CURRENT_QUEUE|QUEUE_CHANGE_TS|**TASK_XML_DATA**|**SCORE_XML_DATA**|
|"12"|"137####_##62###"|"137####_##62###"|"Claim"|"14APR2015:23:36:04"|"AwaitingTriageEast"|"N"|" "|"4"|"."|"<?xml version="1.0" encoding="UTF-8"?><tasks xmlns="xyz.com/abc/wkbh/task">
..... (同上)
任何有关此错误的帮助都会节省我的时间。
【问题讨论】:
-
@amrrs 不要在您不知道自己在说什么时传播误导性信息。
?xmlParse: "解析包含 XML/HTML 内容的 XML 或 HTML 文件或字符串,..." -
@hrbrmstr 也许我不够清楚,请阅读它以字符串形式给出文件名的问题,这就是我的意思,以字符串形式格式化的 XML 当然可以!我认为这是显而易见的,我绝对知道我在说什么!
-
其他人必须相信你的话。
-
我已经删除了我的!谢谢!