Subject: RE: DomParser AND serialize
I need to loop through all documents in a database. For each document old urllinks needs to be replaced by new. These are listed in a config doc.
I’ve tried this way, but have some weird behavior. Bedugging, when returning from the ProcessDOM-sub, the yellow indicator is positionned on the next line (If blnChanged Then), but when I push ‘step into’, the code ends without any reason. No error, no end function… nothing.
Second problem: I don’t want to do the import for documents that don’t need to be changed because no urllinks to replace have been found. I don’t know how to do that…
This is my code (reduced).
Dim blnChanged as Boolean
Sub ProcessDOM(Source As NotesDOMParser)
Dim rootElement As NotesDOMElementNode
Set rootElement = Source.Document.DocumentElement
Dim docList As NotesDOMNodeList
Set docList = rootElement.GetElementsByTagName(“urllink”)
If docList.NumberOfEntries > 0 Then
Dim i As Integer
For i = 1 To docList.NumberOfEntries
Dim eNode As NotesDOMElementNode
Set eNode = docList.GetItem(i)
Dim strAtt As String
strAtt = eNode.GetAttribute(“href”)
Dim strAdjAtt As String
strAdjAtt = strAtt
Dim y As Integer
For y = 0 To Ubound(varOldlink)
strAdjAtt = ReplaceSubstring(Lcase(strAdjAtt), Lcase(Trim(varOldLink(y))), Lcase(Trim(varNewLink(y))))
Next y
If strAtt <> strAdjAtt Then
Call eNode.SetAttribute(“href”, strAdjAtt)
blnChanged = True
End If
Next i
End If
Source.Serialize
End Sub
Function ProcessDatabase(db As NotesDatabase) As Boolean
REM **** INITIALIZE LOCAL ERROR HANDLER
On Error Goto ErrorHandler
ProcessDatabase = False
REM **** DECLARE LOCAL VARIABLES
…
REM **** WALK THROUGH ALL DOCUMENTS IN THE DATABASE
Set dc = db.AllDocuments
Set doc = dc.GetFirstDocument
Do While Not doc Is Nothing
REM ***** EXPORT DOCUMENT TO DXL AND ADJUST LINKS
blnChanged = False
Dim exporter As NotesDXLExporter
Set exporter = session.CreateDXLExporter(doc)
exporter.ExitOnFirstFatalError = False
Dim parser As NotesDOMParser
Set parser = session.CreateDOMParser(exporter)
On Event PostDOMParse From parser Call ProcessDOM
Dim importer As NotesDXLImporter
Set importer = session.CreateDXLImporter(parser, db)
importer.DocumentImportOption = DXLIMPORTOPTION_REPLACE_ELSE_IGNORE
exporter.Process
REM ***** IF CHANGED, LOG REPLACE LINK ACTION
If blnChanged Then
Call LogDocument (LOGTITLE, " Old link(s) have been adjusted in document with docID " & doc.UniversalID, db.Title & " (" & db.FileName & “)”, “”, doc)
End If
NextDocument:
Set doc = dc.GetNextDocument(doc)
Loop
REM **** FUNCTION ENDED SUCCESSFULLY
ProcessDatabase = True
Exit Function
REM **** ERROR HANDLER
ErrorHandler:
Call LogError(LOGTITLE, Err, "ProcessDatabase: " & Error$ & " in line " & Erl)
Resume NextDocument
End Function