0
今日、私はvbaを使ってXML文書からxpathを適用して項目を解析する方法を示したデモを見つけました。それはウェブサイトから同じことをすることが可能な場合はちょうど素晴らしいでしょう。xpathを使ってxml文書を解析してvbaを使用する
Sub XML_Parsing()
Dim xml As Object, post As Object
Set xml = CreateObject("MSXML2.DOMDocument")
xml.async = False: xml.validateOnParse = False
xml.Load (ThisWorkbook.Path & "\htdocs.txt")
For Each post In xml.SelectNodes("//DistributionLists/List")
x = x + 1: Cells(x, 1) = post.SelectNodes(".//Name")(0).Text
Cells(x, 2) = post.SelectNodes(".//TO")(0).Text
Cells(x, 3) = post.SelectNodes(".//CC")(0).Text
Cells(x, 4) = post.SelectNodes(".//BCC")(0).Text
Next post
End Sub
そして、上記のコードはデスクトップに保存されている「htdocs.txt」という名前のテキストファイル上に適用する必要があります。ここでは
は、それがローカルに保存されたファイルから行われている方法です。
<?xml version="1.0" encoding="utf-8"?>
<DistributionLists>
<List>
<Name>Recon</Name>
<TO>John;Bob;Rob;Chris</TO>
<CC>Jane;Ashley</CC>
<BCC>Brent</BCC>
</List>
<List>
<Name>Safety Metrics</Name>
<TO>Tom;Casper</TO>
<CC>Ashley</CC>
<BCC>John</BCC>
</List>
<List>
<Name>Performance Report</Name>
<TO>Huck;Ashley</TO>
<CC>Tom;Andrew</CC>
<BCC>John;Seema</BCC>
</List>
</DistributionLists>
抽出結果:
Recon John;Bob;Rob;Chris Jane;Ashley Brent
Safety Metrics Tom;Casper Ashley John
Performance Report Huck;Ashley Tom;Andrew John;Seema
は今、私は2つの質問を持っている:
1. How to parse the same from a website as i did above, as in "example.com"? If it was "html element" then i could load like "html.body.innerHTML = http.responsetext" but in this case what should be the process?
2. If i do the above thing using EARLY BINDING: what should be the reference to add to the library?