Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML output function

Status
Not open for further replies.

tnayfeh

Programmer
Apr 21, 2004
39
CA
I have a simple function used to export records from a table into a XML format. I can't seem to get the root node schema to print out....what I need is the
"root xmlns:xsd=" xmlns:xsi=" etc...

Am I missing something obvious and simple? :) Here is my code:
Code:
Public Sub testimport()
  
 'Create XMLDOM Object
    Dim xmldoc
    Dim strSql As String
    Dim rs As DAO.Recordset
    Dim db As DAO.Database
    Dim f As Object
    Dim fs As Object

   ' Build the XML document
    Set xmldoc = CreateObject("Microsoft.XMLDOM")
    xmldoc.async = False
    xmldoc.Load ("<?xml version='1.0' encoding='UTF-8' ?>")

   ' Queries the database for class code data
    strSql = "SELECT userclass,definition FROM BUDef"
    Set db = CurrentDb
    Set rs = db.OpenRecordset(strSql, dbOpenDynaset)
    
   
   If (xmldoc.childNodes.length = 0) Then
      
        ' Create root node
        Set root = xmldoc.createNode("element", "root", "")
        xmldoc.appendChild (root)
      
        rs.MoveFirst
  
      'Loop through the recordset
      Do While Not rs.EOF
   
        Set inode = xmldoc.createNode("element", "platformPrivileges", "")
        root.appendChild (inode)
     
        Set child = xmldoc.createNode("element", "platformCode", "")
        child.Text = "Cognos"
        inode.appendChild (child)
     
        Set child = xmldoc.createNode("element", "privilegeCode", "")
        child.Text = rs.fields(0)
        inode.appendChild (child)
     
        Set child = xmldoc.createNode("element", "description", "")
        child.Text = rs.fields(1)
        inode.appendChild (child)

        rs.MoveNext
      Loop

      Set rs = Nothing
   End If

    'Save the XML doc
    xmldoc.Save ("C:\saved.xml")

End Sub

Thanks in advance!
TN
 
>I have a simple function used to export records from a table into a XML format. I can't seem to get the root node schema to print out....
The construction of the function is flawed. There are basic logical and syntactic mistakes.
[tt]
[green]'etc etc[/green]

' Build the XML document
Set xmldoc = CreateObject("Microsoft.XMLDOM")
xmldoc.async = False
[green]'fundamentally wrong[/green]
[red]'[/red]xmldoc.Load ("<?xml version='1.0' encoding='UTF-8' ?>")
[blue]set oprlg=xmldoc.createprocessinginstruction("xml","version='1.0' encoding='UTF-8'")[/blue] [green]'encoding utf-8 may not appear, being default[/green]
[blue]xmldoc.appendchild oprlg
set oprlg=nothing[/blue]

' Queries the database for class code data
strSql = "SELECT userclass,definition FROM BUDef"
Set db = CurrentDb
Set rs = db.OpenRecordset(strSql, dbOpenDynaset)

[green]'again fundamentally wrong:proceeding by mistake![/green]
[red]'[/red]If (xmldoc.childNodes.length = 0) Then

' Create root node
[red]'[/red]Set root = xmldoc.createNode("element", "root", "")
[blue]Set root = xmldoc.createNode([/blue][red]1[/red][blue], "root", "")[/blue]
xmldoc.appendChild (root)

[blue] root.setAttribute "xmlns:xsd"," root.setAttribute "xmlns:xsi","[/blue]

rs.MoveFirst

'Loop through the recordset
Do While Not rs.EOF

Set inode = xmldoc.createNode([red]1[/red], "platformPrivileges", "")
root.appendChild (inode)

Set child = xmldoc.createNode([red]1[/red], "platformCode", "")
child.Text = "Cognos"
inode.appendChild (child)

Set child = xmldoc.createNode([red]1[/red], "privilegeCode", "")
child.Text = rs.fields(0)
inode.appendChild (child)

Set child = xmldoc.createNode([red]1[/red], "description", "")
child.Text = rs.fields(1)
inode.appendChild (child)

rs.MoveNext
Loop

Set rs = Nothing
[red]'[/red]End If

[green]'etc etc...[/green]
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top