On Wednesday, August 19, 2015 at 8:21:50 AM UTC-4, Laura Creighton wrote: > In a message of Wed, 19 Aug 2015 04:57:44 -0700, ryguy7272 writes: > >I'm trying to get R to download the data from here: > > > >http://www.usda.gov/oce/commodity/wasde/report_format/latest-July-2015-New-Format.xml > > > > > ># install and load the necessary package > >install.packages("XML") > >library(XML) > ># Save the URL of the xml file in a variable > > > >xml.url <- > >"http://www.usda.gov/oce/commodity/wasde/report_format/latest-July-2015-New-Format.xml" > ># Use the xmlTreePares-function to parse xml file directly from the web > > > >xmlfile <- xmlTreeParse(xml.url) > ># the xml file is now saved as an object you can easily work with in R: > >class(xmlfile) > > > > > ># Use the xmlRoot-function to access the top node > >xmltop = xmlRoot(xmlfile) > ># have a look at the XML-code of the first subnodes: > >print(xmltop)[1:3] > > > > > > > >Everything seems fine up to that point. The next line seems to NOT parse > >the data as I thought it would. > ># To extract the XML-values from the document, use xmlSApply: > >datacat <- xmlSApply(xmltop, function(x) xmlSApply(x, xmlValue)) > > > > > > > >I did some research on this, and it seemed to work in other examples of xml > >data. I guess this data set is different...or I just don't understand this > >well enough to know what's really going on... > > > >Basically, I want to get this: > > > >xmltop > > > > > >Into a data table. How can I do that? > > > >Thanks. > > This is a mailing list about the Python programming language, not R > xmlSApply is something R uses. The R mailing lists are here: > https://www.r-project.org/mail.html > > When you talk to them, tell them exactly what you were expecting as > a result, what you got instead, and what error messages were generated. > Also let them know what verison of R you are using and what operating > system you are running on. This will make it a lot easier for them > to help you. > > Good luck, > > Laura Creighton
Well, yes, I was originally trying to do it it R, but I couldn't get it working, so I thought I'd try to do it in Python. That was a sample R script. Can I do essentially the same thing in Python? Can I read the XML from the web? http://www.usda.gov/oce/commodity/wasde/report_format/latest-July-2015-New-Format.xml Parse it, or clean it, or whatever, and save it as a CSV or TXT? Is that possible? Thanks. -- https://mail.python.org/mailman/listinfo/python-list