Can I download XML data from the web and save, in as CSV or TXT delimitation?

Laura Creighton lac at openend.se
Wed Aug 19 08:21:07 EDT 2015


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



More information about the Python-list mailing list