Importing XML - "DTD prohibited"

paul_mcc

Registered User.
Local time
Today, 10:38
Joined
Jul 16, 2012
Messages
19
I'm using the below code in an Access form to import XML files.

I get an error 31593, "DTD is prohibited".

How can I fix this?

Thanks in advance,
Paul



Private Sub Command0_Click()

Dim StrFileName As String
Dim fd As FileDialog
Dim vrtSelectedItem As Variant
Dim strprop As String
Dim vbool As Boolean


Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.InitialFileName = "C:\Users\Toshiba\Documents\STEM\data\*.xml"
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems
Application.ImportXML _
DataSource:=vrtSelectedItem, _
ImportOptions:=0

Next vrtSelectedItem
Else
End If
End With
Set fd = Nothing
End Sub
 
is the error on the first file, or a subsequent one

i would try it explicitly with that file.

maybe the file is not a valid xml file.
 
Thanks folks for your ideas.

It does appear to be the file's settings, in the "DTD" as I understand they're called, and it is common to all the files.
 
You might try

ImportOptions:=acStructureAndData
and see if that makes a difference.
 
Thanks jdraw,

That was the first option I had, unfortunately it doesn't seem to work. Cheers for the thought though!

:banghead:
 
Can you post a sample xml file, so we can experiment a bit?
 
I got your file. I have 2003. As a start, I tried importing it through the wizard. It imported correctly. see attached jpg.

It Imports as 2 tables a Header and a Data.
 

Attachments

  • AWF_XML.jpg
    AWF_XML.jpg
    102.5 KB · Views: 693
Yes, from what I'm reading now it seems to be only a problem post-2007. Strange - I wouldn't have thought that would be the case. I took the offending "DTD" sections out of one of the files just now and that seems to do the trick. But what would be preferable, without having to change each of 700 files, is to know what is causing it and make a small settings change, or something similarly easy.
 
I set up a proc to do the import programmatically

Code:
'---------------------------------------------------------------------------------------
' Procedure : AWFXMLIMport
' Author    : Jack
' Date      : 06-11-2012
' Purpose   : Importing an XML file.
'---------------------------------------------------------------------------------------
' Last Modified:
'
' Inputs: N/A
' Dependency: N/A
'--------------------------------------------------------------------------
'
Sub AWFXMLIMport()
Dim StrFileName As String
   Dim fd As FileDialog
   Dim vrtSelectedItem As Variant
   On Error GoTo AWFXMLIMport_Error

    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    With fd
        .InitialFileName = "c:\saample\*.xml"
        If .Show = -1 Then
            For Each vrtSelectedItem In .SelectedItems
          [B]  Debug.Print "Xml File is " & vrtSelectedItem[/B]
                Application.ImportXML _
                    DataSource:=vrtSelectedItem, _
                    ImportOptions:=acStructureAndData
               
            Next vrtSelectedItem
        Else
        End If
    End With
    Set fd = Nothing

   On Error GoTo 0
   Exit Sub

AWFXMLIMport_Error:

    MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure AWFXMLIMport of Module xmlhttp_Etc"
    End Sub

It worked for me with no errors. I added a line Debug.Print to identify the xml file and it is the correct file.

There is no message that a new Table (actually 2 tables Headrow2, Datarow2) as per attached jpg.


Do you have a reference set to Microsoft XML,v6.0 ???
 

Attachments

  • AWF_Xml_viaVBA.jpg
    AWF_Xml_viaVBA.jpg
    91.2 KB · Views: 526
I haven't seen the discussion re post 2007, but you could import as text, remove the offending lines and import the rest as xml. --- If that will resolve the issue, and it can all be automated.

I have samples of getting xml data from online source,(if that is an option- perhaps another data feed) you can see sample at post #6
http://www.accessforums.net/queries/exchange-rate-table-query-28974.html
 
jdraw, thank you very, very much. it's midnight here in West Oz right now so I'll get onto it first thing in the morning and let you know how it goes. Again, thank you - fantastic effort! :D
 
Great stuff -- one of my old work buddies lives in Perth. Good night.
 
jdraw, that worked brilliantly!!! thank you!

i really appreciate all the effort - you've saved us countless hours now.

:D
 

Users who are viewing this thread

Back
Top Bottom