xml


How to Import XML table Google Sheets


so I have a google sheet whereby I want to import F1 qualifying and race results via the ergast.com API. I'm only after the driver and position information from the table, but happy to import the whole table if it's easier. I've tried IMPORTHTML, IMPORTFEED, IMPORTXML but regardless of the query I make, I can't seem to generate any data (just N/A).
The API link for race 1 is: http://ergast.com/api/f1/2016/1/qualifying. URL is in cell A1.
I've tried =IMPORTHTML(A1,"list",0) and also the same with table, but nothing.
I've tried specific xpaths with =IMPORTXML too, but can't seem to get any data to show.
Please can somebody help point me in the right direction to help import this data?
Many thanks.
To import an XML file we could use IMPORTXML or IMPORTDATA.
For the case of using IMPORTXML, it's important to note on the source file if a xmlns is set. On the referred source file the third line,
<MRData xmlns="http://ergast.com/mrd/1.4" series="f1"
url="http://ergast.com/api/f1/2016/1/qualifying" limit="30" offset="0"
total="22">
tell us that a namespace is used (see the xmlns attribute), so we should use wildcards or query for the values of the name attribute.
As the position is an attribute of the elements named Driver, in the following example, the data is retrieved by using to IMPORTXML and arrays:
Example
A1: http://ergast.com/api/f1/2016/1/qualifying
A2: Driver
A3:
={
IMPORTXML(A1,"//*[name()='"&A2&"']/../#position"),
IMPORTXML(A1,"//*[name()='"&A2&"']")
}
NOTE: Some spreadsheet settings require the use of \ instead of , as column separator
Result
+----+--------+----+-----------+------------+------------+------------+
| | A | B | C | D | E | F |
+----+--------+----+-----------+------------+------------+------------+
| 1 | http://ergast.com/api/f1/2016/1/qualifying | |
| 2 | Driver | | | | | |
| 3 | 1 | 44 | Lewis | Hamilton | 1985-01-07 | British |
| 4 | 2 | 6 | Nico | Rosberg | 1985-06-27 | German |
| 5 | 3 | 5 | Sebastian | Vettel | 1987-07-03 | German |
| 6 | 4 | 7 | Kimi | Räikkönen | 1979-10-17 | Finnish |
| 7 | 5 | 33 | Max | Verstappen | 1997-09-30 | Dutch |
| 8 | 6 | 19 | Felipe | Massa | 1981-04-25 | Brazilian |
| 9 | 7 | 55 | Carlos | Sainz | 1994-09-01 | Spanish |
| 10 | 8 | 3 | Daniel | Ricciardo | 1989-07-01 | Australian |
| 11 | 9 | 11 | Sergio | Pérez | 1990-01-26 | Mexican |
| 12 | 10 | 27 | Nico | Hülkenberg | 1987-08-19 | German |
| 13 | 11 | 77 | Valtteri | Bottas | 1989-08-29 | Finnish |
| 14 | 12 | 14 | Fernando | Alonso | 1981-07-29 | Spanish |
| 15 | 13 | 22 | Jenson | Button | 1980-01-19 | British |
| 16 | 14 | 30 | Jolyon | Palmer | 1991-01-20 | British |
| 17 | 15 | 20 | Kevin | Magnussen | 1992-10-05 | Danish |
| 18 | 16 | 9 | Marcus | Ericsson | 1990-09-02 | Swedish |
| 19 | 17 | 12 | Felipe | Nasr | 1992-08-21 | Brazilian |
| 20 | 18 | 26 | Daniil | Kvyat | 1994-04-26 | Russian |
| 21 | 19 | 8 | Romain | Grosjean | 1986-04-17 | French |
| 22 | 20 | 21 | Esteban | Gutiérrez | 1991-08-05 | Mexican |
| 23 | 21 | 88 | Rio | Haryanto | 1993-01-20 | Indonesian |
| 24 | 22 | 94 | Pascal | Wehrlein | 1994-10-18 | German |
+----+--------+----+-----------+------------+------------+------------+

Related Links

XQuery request opens whole file
getting parent node according two child node text XPATH
identity constraint key matches more than one value within the scope of its selector
Where to find/how to extract image hyperlinks from zipped docx document?
How do you echo a question mark in a shell script?
While transforming a xml to xml using xsl 1.0. xsl:attribute: Cannot add attributes to an element if children have been already added to the element
Can you declare and use a variable inside an XML without using XSL to transform/parse the XML
lxml and xml namespaces - Using find and findall to get XML Tag Value
cvc-complex-type.2.4.d: Invalid content was found starting with element 'testResources'. No child element is expected at this point
Using a webservice in Delphi by manually building XML (i.e. bypassing WSDL)
Validate Xml with XSd without using XSD physical path
How do I add line breaks after each tag in MSXML?
writing groovy script for REST service in SOAP UI
Logic for xsl:for is not clear
Dynamic cron Magento
VBA XML ChildNodes

Categories

HOME
batch-file
windows
phantom-dsl
httparty
checkstyle
forms
wakanda
apache-spark-mllib
can
static-site
xbee
iis-6
banner
vimdiff
ibeacon-android
windows-ce
ipmitool
naivebayes
tput
endpoint
frequency-distribution
http-post
package.json
dimensional-modeling
database-connection
windows-xp
lilypond
simpleitk
direct3d11
perlbrew
windows-server-2003
tiki-wiki
soot
failover
utorrent
deltaspike
quickfixj
jett
github3.py
openwhisk
getpixel
mnist
processwire
xajax
android-augmented-reality
connection-pool
metawidget
typesafe-config
hackintosh
naming
linter
mschart
dbcontext
tinymce-3
x-ray
yii2-user
rackspace-cloud
flyout
mathcad
reporting-services-2012
x-tag
xdoclet
spreadjs
project-organization
cycle2
contentcontrol
highland.js
atan2
lazybones
flock
uvc
dbaccess
deform
contrast
appserver
jqmodal
cuba
functional-java
c++builder-xe5
scringo
insert-id
virtual-pc
resource-management
robotlegs
dopostback
monotouch.dialog
iboutlet
cgimage
entity-attribute-value
saxparseexception
filemerge
u2netdk
winmain
update-statement
tabpanel
blender-2.49
web-application-project
cuda.net
cldc
product-management
mathematical-typesetting

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App