tags:

views:

319

answers:

4

How can I extract raw Xml text from an MSXML2 - IXMLDOMNodeList in Microsoft Access?

+1  A: 

You could use the Xml property on each IXmlDomNode.

Wim Coenen
A: 

You'll do this with VBA.

Add the corresponding msxml dll to your tools

write some code like this one:

Public Function getFromXML(x_fileXML as string) as string

On Error GoTo ERREUR

      Dim doc_xml As MSXML2.DOMDocument, _
          list_xml As IXMLDOMNodeList, _ 
          i As Long, _
          m_getFromXML as string


Set doc_xml = New MSXML2.DOMDocument

doc_xml.Load x_fileXML

'i am interested by the nodeLists having a "attributeType: tag"'
Set list_xml = doc_xml.getElementsByTagName("s:AttributeType")
For i = 0 To (list_xml.Length - 1)
     'extract the requested data here'
     'something like m_getFromXML = m_getFromXML & ";" & ...'
Next i

getFromXML = m_getFromXML

This was written on the fly. Please check the objects to be closed/set to nothing before leaving the proc.

Philippe Grondier
+1  A: 
A: 

This really depends on what you plan to do with the xml. In access 2003, and 2007 we can import xml.

So, if you have a xml string that is a table of data, then you could receive the data, write out to disk, and then execute a Application.ImportXML. This approach is FAR less code then other answers given here.

Here is a code snip this concept:

Dim intF       As Integer
Dim strF       As String
Dim objXML     As Object

Set objXML = CreateObject("MSXML2.XMLHTTP")
objXML.Open "GET", "URL string here", False
objXML.Send

strF = "c:\t.xml"
intF = FreeFile
Open strF For Output As intF
Write #intF, objXML.responsetext
Close

Application.ImportXML "c:\t.xml", acAppendData

The above would assume that the XML has a catalog, or table def in the text

eg:

<CATALOG>
<tblContacts>
<ID>1</ID>
<Last_x0020_Name>Kallal</Last_x0020_Name>
<First_x0020_Name>Albert</First_x0020_Name>
</tblContacts>
<tblContacts>
<ID>2</ID>
<Last_x0020_Name>Smo</Last_x0020_Name>
<First_x0020_Name>Joe</First_x0020_Name>
</tblContacts>
</CATALOG>
Albert D. Kallal