Vielleicht hab ich Dich auch noch immer nicht verstanden, aber Du möchtest eine Datei einlesen und daraus dann Notesdokumente machen?
Diesen Agenten hab ich mal gebastelt und er funktioniert eigentlich auch. Es wird eine .xml-Datei eingelesen und daraus Dokumente und Antwortdokumente generiert:
Declarations:
Dim domParser As NotesDOMParser
Initialize:
Sub Initialize
Dim session As NotesSession
Dim Workspace As New NotesUIWorkspace
Dim db As NotesDatabase
Dim inputStream As NotesStream
Dim docNode As NotesDOMDocumentNode
Dim a As notesDOMNode
Dim node As NotesDOMNode
Dim automatname As String
Dim checkview As notesview
Dim checkdoc As NotesDocument
Dim nextcheckdoc As NotesDocument
Dim checkcoll As NotesDocumentcollection
'#############################################################################
Dim origXML As String
' Variable für die XML-Datei
Dim xmlFilename As Variant
xmlFilename = Workspace.OpenFileDialog( False , "Aus welcher XML-Datei soll importiert werden?"_
,"XML-Files|*.xml", "W:\test\termi.xml" , "*.xml" )'"W:\test\termi.xml" '"W:\test\golem\xml\termi.xml"
If Isempty(xmlFilename) Then
Exit Sub
End If
origXML = xmlFilename(0)
'#############################################################################
Set session = New NotesSession
Set db = session.CurrentDatabase
'########################################
Set checkview = db.GetView("automatname")
'########################################
'open the XML file
Set inputStream = session.CreateStream
inputStream.Open (origXML)
'create DOM parser and process
Set domParser=session.CreateDOMParser(inputStream)
domParser.Process
'get the document node
Set docNode = domParser.Document
'############
Dim child As NotesDOMNode
'Dim eNode As NotesDOMElementNode
Dim numChildNodes As Integer
Dim firstdoc As NotesDocument
Dim childdoc As NotesDocument
Set node = docnode
If Not node.IsNull Then
Set child = node.LastChild ' Get the last node
Dim numAttributes As Integer, numChildren As Integer
numAttributes = child.attributes.numberofentries
Set node = child
Stop
Set firstdoc = db.CreateDocument()
firstdoc.Form = Node.NodeName
Dim i As Integer
Dim feldname As String
Dim feldwert As String
Dim item As NotesItem
Dim attrs As notesdomnamednodemap
Set attrs = Node.Attributes ' Get attributes
For i = 1 To numAttributes ' Loop through them
Set a = attrs.GetItem(i)
feldname = a.NodeName
If feldname = "xmlns:xsi" Then
Goto weiter
End If
If feldname = "xsi:noNamespaceSchemaLocation" Then
feldname = "schema"
End If
feldwert = a.NodeValue
Set item = firstdoc.ReplaceItemValue( "att_"+feldname, feldwert )
weiter:
Next
'#############################################################################################
Set checkdoc = checkview.GetDocumentByKey(firstdoc.att_name(0)) ' Prüfen ob es diesen
'Automaten schon gibt
Dim meldung As Integer
If Not checkdoc Is Nothing Then
meldung = Messagebox ("Dieser GeVo ist schon modelliert!"_
+Chr(10)+"Wollen Sie diesen ersetzen?", 3 + 32 , "GeVo ersetzen?")
If meldung = 2 Or meldung = 7 Then ' bei "Abbruch" oder "Nein"
Exit Sub
Else ' bei "OK" zum Überschreiben der alten Datensätze
Set checkcoll = checkview.GetAllDocumentsByKey(checkdoc.att_name(0))
Set checkdoc = checkcoll.GetFirstDocument
Do
Set nextcheckdoc = checkcoll.GetNextDocument(checkdoc)
Call checkdoc.Remove(True)' Löschen der alten Datensätze
Set checkdoc = nextcheckdoc
Loop Until checkdoc Is Nothing
End If
End If
'#############################################################################################
Call firstdoc.ComputeWithForm(True, True)
automatname = firstdoc.key_za(0)
Call firstdoc.Save( True, True )
End If
Set child = node
Call walkNameValue(child, firstdoc,automatname) ' kind übergeben und alle anderen kinder in der
' sub abarbeiten
End Sub
Sub "walkNameValue":
Sub walkNameValue ( node As NotesDOMNode, firstdoc As NotesDocument, automatname As String)
' hier werden alle doks zu nodes angelegt, die direkt unter
' dem zustandsautomaten stehen
Dim child As NotesDOMNode
Dim nextchild As NotesDOMNode
Dim numChildNodes As Integer
Dim childnumChildNodes As Integer
Dim session As NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim childdoc As NotesDocument
Dim numAttributes As Integer, numChildren As Integer
Dim a As notesDOMNode
Set session = New NotesSession
Set db = session.CurrentDatabase
If Not node.IsNull Then
Set child = node.FirstChild ' Get the first node
numChildNodes = node.NumberOfChildNodes
Do
Select Case child.NodeType
Case DOMNODETYPE_ELEMENT_NODE:
numAttributes = child.attributes.numberofentries
Set doc = db.CreateDocument()
doc.Form = child.NodeName
Dim i As Integer
Dim feldname As String
Dim feldwert As String
Dim item As NotesItem
Dim attrs As notesdomnamednodemap
Set attrs = child.Attributes ' Get attributes
For i = 1 To numAttributes ' Loop through them
Set a = attrs.GetItem(i)
feldname = a.NodeName
If feldname = "xmlns:xsi" Then
Goto weiter
End If
If feldname = "xsi:noNamespaceSchemaLocation" Then
feldname = "schema"
End If
feldwert = a.NodeValue
Set item = doc.ReplaceItemValue( "att_"+feldname, feldwert )
weiter:
Next
Call doc.MakeResponse(firstdoc)
doc.key_za = automatname
Call doc.Save( True, True )
End Select
childnumChildNodes = child.NumberOfChildNodes ' hat das node noch kinder
If childnumChildNodes >0 Then
Set nextchild = child.FirstChild
Do
Call walkNameValuechild(nextchild, doc, automatname) ' kind übergeben und alle anderen kinder in der
' sub abarbeiten
Set nextchild = nextchild.NextSibling
childnumChildNodes = childnumChildNodes-1
Loop Until childnumChildNodes = 0
End If
Set child = child.NextSibling
numChildNodes = numChildNodes-1
Loop Until numChildNodes = 0
Stop
End If
End Sub
Sub "walkNameValuechild":
Sub walkNameValuechild ( node As NotesDOMNode, doc As notesdocument, automatname As String)
Dim child As NotesDOMNode
Dim nextchild As NotesDOMNode
Dim numChildNodes As Integer
Dim childnumChildNodes As Integer
Dim session As NotesSession
Dim db As NotesDatabase
Dim childdoc As NotesDocument
Dim a As notesDOMNode
Set session = New NotesSession
Set db = session.CurrentDatabase
Select Case node.NodeType
Case DOMNODETYPE_ELEMENT_NODE: ' Most nodes are Elements
Stop
Dim numAttributes As Integer, numChildren As Integer
numAttributes = node.attributes.numberofentries
'##########################################################################
Set childdoc = db.CreateDocument()
childdoc.Form = node.NodeName
Dim i As Integer
Dim feldname As String
Dim feldwert As String
Dim item As NotesItem
Dim attrs As notesdomnamednodemap
Set attrs = node.Attributes ' Get attributes
For i = 1 To numAttributes ' Loop through them
Set a = attrs.GetItem(i)
feldname = a.NodeName
If feldname = "xmlns:xsi" Then
Goto weiter
End If
If feldname = "xsi:noNamespaceSchemaLocation" Then
feldname = "schema"
End If
feldwert = a.NodeValue
Set item = childdoc.ReplaceItemValue( "att_"+feldname, feldwert )
weiter:
Next
Call childdoc.MakeResponse(doc)
childdoc.key_za = automatname
Call childdoc.Save( True, True )
Do
childnumChildNodes = node.NumberOfChildNodes ' hat das node noch kinder
If childnumChildNodes >0 Then
Set nextchild = node.FirstChild
Do
Call walkNameValuechild(nextchild, childdoc, automatname) ' kind übergeben und alle anderen kinder in der
' sub abarbeiten
Set nextchild = nextchild.NextSibling
childnumChildNodes = childnumChildNodes-1
Loop Until childnumChildNodes = 0
If childnumChildNodes > 0 Then
Set child = child.NextSibling
numChildNodes = numChildNodes-1
End If
End If
Loop Until numChildNodes = 0
Exit Sub
End Select 'node.NodeType
End Sub