Makro: Preberi SQL stavek iz XML datoteke
Združljivost | VB/VBA MSXML.4 |
Prispevek / Article | Uvozimo podatke o kontaktih iz Birokrata v Outlook |
Opis / Summary |
Makro iz XML datoteke prebere ustrezno SQL poizvedbo. Iskanje posameznega vozlišča poteka s pomočjo XPath poizvedbe. Function reads SQL statement from XML file. Particular node is located with XPath query. |
Odvisnosti / Dependencies | preddefinirana XML datoteka (glej primer spodaj)
predefined XML file (see the example bellow) |
Public Function SQL(aName As String, aType As String) As String On Error GoTo ErrorHandler Dim oXmlDoc As DOMDocument Dim oXmlNode As IXMLDOMNode Dim aXPathQry As String aXPathQry = "//database/connection/queries/query[@name='{0}' and @type='{1}']" aXPathQry = Replace(aXPathQry, "{0}", aName) aXPathQry = Replace(aXPathQry, "{1}", aType) Set oXmlDoc = New DOMDocument oXmlDoc.Load "C:\MiniIS\cfg\config.xml" Set oXmlNode = oXmlDoc.SelectSingleNode(aXPathQry) If Not (oXmlNode Is Nothing) Then SQL = oXmlNode.Text End If FinalHandler: Set oXmlNode = Nothing Set oXmlDoc = Nothing Exit Function ErrorHandler: MsgBox Err.Description, vbOKOnly + vbExclamation, _ "[DBUti.SQL] Napaka: " & Err.Number Resume FinalHandler End Function
Primer XML datoteke / XML file example:
<?xml version='1.0'?> <database> <connection name="somename" value="Provider=SQLOLEDB;Data Source=SERVERNAME;Initial Catalog=DBNAME;User Id=USR;Password=PWD" > <queries> <query name="q1" type="select"> ... SQL goes here ... </query> <query name="q2" type="update"> ... SQL goes here ... </query> </queries> </connection> </database>