谷歌电子表格importxml:如何获取XML中元素节点的所有名称 [英] Google spreadsheet importxml : how to grab all names of element nodes in XML

查看:83
本文介绍了谷歌电子表格importxml:如何获取XML中元素节点的所有名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用importxml函数导入XML.

I'm trying to use importxml function to import XML.

<item>
    <name>James</name>
    <date>11/11/2016</date>
    <description>Student</description>
</item>

如果我使用

=importxml(URL, "//item")

我可以导入信息,但不能导入每个信息的名称.

I can import the information, but not the names of each information.

我想拉这样的东西

name      date       description
James     11/11/2016 Student

任何xPath函数可以做到这一点吗?

Any xPath function to do this?

推荐答案

您可以使用以下公式获取标头:

You can get the headers with this formula:

=unique(arrayformula(regexreplace(transpose(split(IMPORTDATA(A1),"><",false)),">.*|\/","")))

基本上,我要做的是使用importdata提取页面上的所有内容,然后使用split和transpose函数,我强迫它根据每个嵌套项><进行拆分,transpose则是垂直交换它.

Basically what I do, is use importdata to pull everything on the page, then using split and transpose functions, I force it to split based on each nested item >< , transpose is to swap it vertically.

到那时,您将看到:

然后将regexreplace与arrayformula一起使用,我用">.*|\/"删除标头之后的所有数据,然后使用unique给我所有标头的最终唯一列表.

Then using regexreplace with arrayformula I remove all the data after the headers with ">.*|\/" and then use unique to give me a final unique list of all headers.

这篇关于谷歌电子表格importxml:如何获取XML中元素节点的所有名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆