Я хочу создать dataframe из файла XML. Мне нужны только определенные узлы, и я хочу их упорядочить так, чтобы я мог легко работать с данными.Правильный формат данных R & XML
Меня интересует только содержание различных узлов <stroke>
. Что мне нужно <starttime>
и <endtime>
, также <bounds>
со всеми подузлами и всех <sample>
узлов с <x>
, <y>
и <time>
подузлами.
Это мой текущий код:
file <- "1.xml"
xmlfile <- xmlTreeParse(file)
xmltop <- xmlRoot(xmlfile)
values <- xmlSApply(xmltop, function(x) xmlSApply(x, xmlValue))
df <- data.frame(t(values),row.names=NULL)
Интересная часть данных-кадра, содержащего данные обводки выглядит следующим образом:
UnassignedStrokes 1 1459867893629, 1459867896812, 145986789362914598678948151.0-14090101260.0750.0217.018.0260.625766.01459867893629108260.625763.6251459867893722120262.875762.01459867893775122278.0757.1251459867893935124294.875755.751459867894015124304.875755.1251459867894055124319.125755.3751459867894109124326.75754.751459867894135124355.0756.51459867894229124372.375756.3751459867894282124388.625755.3751459867894335124401.375756.1251459867894375124427.75754.3751459867894469124448.75752.1251459867894549124455.5750.8751459867894575124473.75751.251459867894669124476.125752.01459867894789124474.25751.751459867894802118469.875750.7514598678948150, 145986789589214598678968121.0-14090101364.0701.010.0125.0364.5701.0145986789589232366.0702.01459867895905106367.25702.6251459867895958120367.5703.1251459867896012122369.25724.1251459867896358126369.375748.01459867896465126370.125765.01459867896532126369.875779.51459867896598126369.125789.1251459867896638126369.375795.251459867896665126370.875803.751459867896705126373.125825.6251459867896812126
.
Кажется, что все значения подузлов находятся в очереди, что затрудняет работу с ним. Что там произошло и что я могу сделать, чтобы отформатировать это правильно?
Это снимок моих данных XML:
<?xml version="1.0" encoding="UTF-8" ?>
<page>
<id>1459867896812</id>
<bookId>1459867896812</bookId>
<paperspace>21.49.16.203</paperspace>
<checkDate>2016-04-05 16:51:36.812</checkDate>
<penCheckDate>2016-04-05 16:51:36.812</penCheckDate>
<receiveDate>2016-04-05 16:51:48.363</receiveDate>
<pageNr>203</pageNr>
<pages>1</pages>
<processStatus>received</processStatus>
<penData>
<expiration>0</expiration>
<signature/>
<toEnterprise>1</toEnterprise>
<company>Universitaet Muenster</company>
<mandator>Uni_Muenster</mandator>
<comment>Universitaet Muenster</comment>
<pagesToComplete/>
<previousPages>0</previousPages>
<clientAttribute name="vertrag">XXXX</clientAttribute>
</penData>
<bounds>
<x>260.0</x>
<y>701.0</y>
<width>217.0</width>
<height>125.0</height>
</bounds>
<UnassignedStrokes>
<starttime>1459867893629</starttime>
<endtime>1459867896812</endtime>
<stroke>
<starttime>1459867893629</starttime>
<endtime>1459867894815</endtime>
<linewidth>1.0</linewidth>
<color>-14090101</color>
<bounds>
<x>260.0</x>
<y>750.0</y>
<width>217.0</width>
<height>18.0</height>
</bounds>
<sample>
<x>260.625</x>
<y>766.0</y>
<time>1459867893629</time>
<force>108</force>
</sample>
<sample>
<x>260.625</x>
<y>763.625</y>
<time>1459867893722</time>
<force>120</force>
</sample>
<sample>
<x>262.875</x>
<y>762.0</y>
<time>1459867893775</time>
<force>122</force>
</sample>
<sample>
<x>278.0</x>
<y>757.125</y>
<time>1459867893935</time>
<force>124</force>
</sample>
<sample>
<x>294.875</x>
<y>755.75</y>
<time>1459867894015</time>
<force>124</force>
</sample>
<sample>
<x>304.875</x>
<y>755.125</y>
<time>1459867894055</time>
<force>124</force>
</sample>
<sample>
<x>319.125</x>
<y>755.375</y>
<time>1459867894109</time>
<force>124</force>
</sample>
<sample>
<x>474.25</x>
<y>751.75</y>
<time>1459867894802</time>
<force>118</force>
</sample>
<sample>
<x>469.875</x>
<y>750.75</y>
<time>1459867894815</time>
<force>0</force>
</sample>
</stroke>
<stroke>
<starttime>1459867895892</starttime>
<endtime>1459867896812</endtime>
<linewidth>1.0</linewidth>
<color>-14090101</color>
<bounds>
<x>364.0</x>
<y>701.0</y>
<width>10.0</width>
<height>125.0</height>
</bounds>
<sample>
<x>364.5</x>
<y>701.0</y>
<time>1459867895892</time>
<force>32</force>
</sample>
<sample>
<x>366.0</x>
<y>702.0</y>
<time>1459867895905</time>
<force>106</force>
</sample>
<sample>
<x>367.25</x>
<y>702.625</y>
<time>1459867895958</time>
<force>120</force>
</sample>
<sample>
<x>367.5</x>
<y>703.125</y>
<time>1459867896012</time>
<force>122</force>
</sample>
<sample>
<x>369.25</x>
<y>724.125</y>
<time>1459867896358</time>
<force>126</force>
</sample>
<sample>
<x>369.375</x>
<y>748.0</y>
<time>1459867896465</time>
<force>126</force>
</sample>
<sample>
<x>370.125</x>
<y>765.0</y>
<time>1459867896532</time>
<force>126</force>
</sample>
<sample>
<x>369.875</x>
<y>779.5</y>
<time>1459867896598</time>
<force>126</force>
</sample>
<sample>
<x>369.125</x>
<y>789.125</y>
<time>1459867896638</time>
<force>126</force>
</sample>
<sample>
<x>369.375</x>
<y>795.25</y>
<time>1459867896665</time>
<force>126</force>
</sample>
<sample>
<x>370.875</x>
<y>803.75</y>
<time>1459867896705</time>
<force>126</force>
</sample>
<sample>
<x>373.125</x>
<y>825.625</y>
<time>1459867896812</time>
<force>126</force>
</sample>
</stroke>
</UnassignedStrokes>
</page>
ОК, спасибо сначала! Я понял проблему и попытался ее решить сейчас :-) – Flugmango