[R] Trouble with reading xml in R

2013-04-30 Thread Dorte Klerke

 Hi I have been trying for days now to read the contents of this xml file into
R. I tried the simpler solution xmlToDataFrame, which worked on another
file, but somehow it doesn't work for this file. 
 
I have tried different other solutions, but I just can't seem to get it
quite right. 
 
doc - xmlRoot(xmlTreeParse(url)) 
art - doc[[1]] [[DeliveryDay]] 
fields - xmlApply(art[[2]]), names) 
 
unique(names(unlist(fields))) 
 
Gives output: 
 TimeStepID.text Purchase.Price Purchase.Volume Sell.Price
 Sell.Volume 
 
 
So I want the result to be a 2 data.frames which looks like this (of course
for the sell data.fram it would say sell) 
 
 
TimeStepID   Purchase.PricePurchase.Volume 
1  3000  13000 
1  2900  13400 
- 
24   2000   12333 
 
etc. 
 
How is this possible? 
 
 
Also an extra question. My filename is called something like (a new file
every day) 
 
BidAskCurves_DE-AU_20130425_20130424130349.xml 
 
The first part after the AU is the current date, this I can generate
automacticly but I can't generate the last since its the date, time, minute
and second of the time the data was uploaded from another party to their ftp
- where I'm getting the data. 
 
Is there anyway to get R to find the right file, when I can only generate
part of the file? 
  __
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Trouble with reading xml in R

2013-04-30 Thread Barry Rowlingson
On Tue, Apr 30, 2013 at 5:12 PM, Dorte Klerke dkle...@hotmail.com wrote:

  Hi I have been trying for days now to read the contents of this xml file into
 R. I tried the simpler solution xmlToDataFrame, which worked on another
 file, but somehow it doesn't work for this file.


 How is this possible?

 How is this possible without sending us the file? EFORGOTATTACHMENT?


 Also an extra question. My filename is called something like (a new file
 every day)

 BidAskCurves_DE-AU_20130425_20130424130349.xml

 The first part after the AU is the current date, this I can generate
 automacticly but I can't generate the last since its the date, time, minute
 and second of the time the data was uploaded from another party to their ftp
 - where I'm getting the data.

 Is there anyway to get R to find the right file, when I can only generate
 part of the file?

 The dir() function has a pattern argument, so you can do:

dir(/myfolder,pattern=BidAskCurves_DE-AU_20130425_[0-9]*.xml) # untested

to list all files that match that pattern in that folder.

the pattern is a 'regular expression', so you might have to
backslashify special characters, but - and _ aren't special.

Barry

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.