2

我有一个这样的 XML 文件:

<Example>
  <A>
    <a1>1</a1>
    <a2>2</a2>
  </A>
  <B>
    <b1>1</b1>
    <b2>2</b2>
    <b3>3</b3>
  </B>
  <B>
  .
  .
  .
  </B>
</Example>

当我使用Application.ImportXML Me.XMLpath, acStructureAndData时,它会同时导入表 A 和 B。那么我怎么能只导入表 B 而没有 A 呢?(A 可能是 10 多个不同的表)。感谢您的热心帮助!

4

1 回答 1

1

感谢您的提示,以下是我所做的...

Dim db As Database
Set db = CurrentDb()
Dim xDoc As MSXML.DOMDocument
Set xDoc = New MSXML.DOMDocument
Dim xNote As IXMLDOMNode
Dim x As IXMLDOMNodeList
Dim XMLpath, sSQL As String

XMLpath = Me.Text1
xDoc.validateOnParse = False
sSQL = "INSERT INTO Temp VALUES ('"

If xDoc.Load(XMLpath) Then
    Set x = xDoc.getElementsByTagName("_TargetTag")
Else
    MsgBox "XML file ERROR"
    Exit Sub
End If

For j = 0 To x.length - 1
    For i = 0 To lengthOfChildNode
        sSQL = sSQL & x(j).childNodes(i).nodeTypedValue & "','"
    Next i
    sSQL = Left(sSQL, Len(sSQL) - 2) & ");"
    db.Execute sSQL
    sSQL = "INSERT INTO Temp VALUES ('"
Next j

到目前为止,我得到了我需要的东西,但是任何可以改进此代码的想法我都会非常感激。谢谢!

于 2012-12-05T20:23:46.013 回答