简体   繁体   中英

Google Sheet importxml create table from xml file

Trying to use importxml in google-sheets. My XML file is something like this:

<file>
<file_name>file1</file_name>
<file_id>407897</file_id>
<disk_id>180622</disk_id>
</file>

There are tons of files in this xml ~5k. I'm trying to have a table in a google-sheet like this below:

col 1 | col 2 | col 3
file1 | 001   | 001
file2 | 002   | 002

Now sometimes file doesn't have a disk id so it would be:

  <files>
    <file>
    <file_name>file1</file_name>
    <file_id>1</file_id>
    <disk_id>1</disk_id>
    </file>
    <file>
    <file_name>file2</file_name>
    <file_id>2</file_id>
    </file>
    <file>
    <file_name>file3</file_name>
    <file_id>3</file_id>
    <disk_id>1</disk_id>
    </file>
<files>

Table I want to create would something like this:

col 1 | col 2 | col 3
file1 | 001   | 001
file2 | 002   | 
file2 | 002   | 001

I tried using:

=importxml("url","//file_name | //file_id | //disk_id")

This gave me something like this (single column):

file1
001
001
file2
002
file3
003
001

and adding transpose it gave something like this:

=transpose(importxml("url","//file_name | //file_id | //disk_id"))

file1 001 001 file2 002 file3 003 001

Is there any way to get this using importxml in google-sheets?

You are very close to reaching your goal. You only need to modify the XPath in the IMPORTXML formula to read rows instead of attributes. Based on your example XML, you want something like this:

=IMPORTXML("{XML URL}","/FILES//FILE")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM