0

我有 3000 个带有书籍元数据的 ONIX 风格的 xml URL。我想从这些文件中过滤出一些节点,并将它们解析为单个工作表中的 Excel 行。

这是 XML 路径的示例:http: //btsoep.appspot.com/rest/book/9789082516425

我想将这些 XML 数据过滤为

<Product>
 <Title>
  <TitleText>

<Product>
 <Contributor>
  <PersonName>

我需要在 Excel 工作表中检索到的数据,其中每个 URL 都有自己的行。所以 URL 在 A 行,TitleText 在 B 行,PersonName 在 C 行。

我该怎么做?

编辑1:

到目前为止,我尝试过的是:-首先使用 wget 下载所有 xml 数据,然后尝试批量解析这是 excel。这可以工作,但没有必要。- 在 Excel 中使用默认的 XMLimport 函数。我似乎无法批量运行它。

我没有任何过滤 XML 文件并在 Excel 工作表中解析它的经验。我没有要求任何人为我解决这个问题或为我编写代码,但我希望朝着好的方向迈出一步。哪种工具最适合这种情况?再次感谢。

4

1 回答 1

0

这应该让你开始

Option Explicit

Sub parseONIX()

    Dim URL As String

    URL = "http://btsoep.appspot.com/rest/book/9789082516425"
 '  URL = "https://www.w3schools.com/xml/plant_catalog.xml"

    Dim XMLPage As New MSXML2.XMLHTTP60
    XMLPage.Open "GET", URL, False
    XMLPage.send

    Dim XMLDoc As New MSXML2.DOMDocument
    XMLDoc.LoadXML XMLPage.responseText

    Debug.Print XMLDoc.ChildNodes(0).BaseName
    Debug.Print XMLDoc.ChildNodes(1).BaseName
    Debug.Print XMLDoc.ChildNodes(1).ChildNodes(0).BaseName
    Debug.Print XMLDoc.ChildNodes(1).ChildNodes(1).BaseName
    Debug.Print XMLDoc.getElementsByTagName("Product").Item(0).BaseName

    Dim i As Integer

    For i = 0 To XMLDoc.getElementsByTagName("Measure").Length - 1

        Debug.Print "type: "; XMLDoc.getElementsByTagName("Measure")(i).ChildNodes(0).Text,
        Debug.Print XMLDoc.getElementsByTagName("Measure")(i).ChildNodes(1).Text,
        Debug.Print XMLDoc.getElementsByTagName("Measure")(i).ChildNodes(2).Text

    Next i



End Sub
于 2017-09-06T17:14:19.217 回答