Change links using NotesDXLExporter and NotesDXLImporter

I have to change urllinks in almost 3000 notesdatabases.Using a LotusScript agent, I need to loop through all documents in those databases, search for the old links in the rich text fields and if old links are found, I have to change them into the new ones.

Can anyone tell me how I can do this using Release 6-code (ex. NotesDXLExporter and NotesDXLImporter classes). I’m new in this R6 code.

Subject: change links using NotesDXLExporter and NotesDXLImporter

Here’s a function I have used for a similar purpose. Run it on a sample document and get the DXL so you will know what to replace. Note that you’ve got to be sure the links are all in the same format or else this could cause document corruption. Also note that you cannot modify the dxl string in any way if it is a large string (such as when the document contains an image). There is a limit to how big a string can be. But if you don’t mess with it, there is basically no limit – which allows this simple replace to work.

Function ReplaceDXLString(curdoc As notesdocument, oldtext As String, newtext As String)

On Error Goto ErrHandle

'export dxl

Dim docdxl As String

Dim exporter As NotesDXLExporter

Set exporter = cfs.CreateDXLExporter

docdxl = exporter.Export(curdoc)





Dim unfixed As String

unfixed = docdxl



'change dxl

docdxl = Replace(docdxl, oldtext, newtext)



'Call quicksend(cfdb, "Chris Crompton/person/dev/diamax", "DXL Output", docdxl)

Dim newdoc As notesdocument

Set newdoc = cfdb.createdocument

With newdoc

	.title="DXL sample"

	.form = "dxl"

	.body = docdxl

'SAVE THIS IF YOU WANT TO VIEW THE DXL OF THE DOCUMENT SO YOU KNOW WHAT TO REPLACE

	'.save True, True

End With





'import dxl

Dim importer As NotesDXLImporter

Set importer = cfs.CreateDXLImporter(docdxl, cfdb)

importer.DocumentImportOption = DXLIMPORTOPTION_UPDATE_ELSE_IGNORE

Call importer.Process

replacedxlstring = 1

'Msgbox importer.log

exitnow:

Exit Function

errhandle:

'Print importer.log

'Call LogErrorEx(importer.log, SEVERITY_HIGH, curdoc)

'outputError("Error " & Err & " on line " & Erl & ": " & Error(Err) & " (Details sent to OpenLog)")

'Call LogError

replacedxlstring = 0

Resume exitnow

Exit Function

End Function

Subject: RE: change links using NotesDXLExporter and NotesDXLImporter

Thanks for the help Christopher, but I don’t think this code will work for what I need to do. I have to change the href attribute of a hotspot, and not just text in a document.

I already got the next code working correct:

REM **** INITIALIZE LOCAL ERROR HANDLER

On Error Goto ErrorHandler

ProcessDatabase = False

REM **** DECLARE LOCAL VARIABLES

Dim dc As NotesDocumentCollection

Dim doc As NotesDocument

Dim exporter As NotesDXLExporter

Dim importer As NotesDXLImporter

Dim parser As NotesDOMParser

Dim node As NotesDOMDocumentNode

Dim nodelist As NotesDOMNodeList

Dim linknode As NotesDOMElementNode

Dim i As Long

Dim x As Integer

Dim intCount As Integer

Dim strLink As String

Dim boolLogIt As Boolean

Dim exportSucceeded As Boolean

REM **** DEFINE DOM OBJECTS

Set exporter = session.CreateDXLExporter

Set parser = session.CreateDOMParser

REM **** START OF DATABASE TO BE PROCESSED

Call agentLog.LogAction("ProcessDatabase: Processing database " & db.Title)

REM **** WALK THROUGH ALL DOCUMENTS IN THE DATABASE

Set dc = db.AllDocuments

Set doc = dc.GetFirstDocument

Do While Not doc Is Nothing

intCount = 0

strHREFs = “”

boolLogIt = False

REM ***** TRANSFORM DOCUMENT TO DXL AND WALK THROUGH LINKS TO LOOKUP REFERENCES TO NETWORK DRIVES

Call exporter.SetInput(doc)

Call exporter.SetOutput(parser)

exporter.ExitOnFirstFatalError = False

exportSucceeded = False

Call exporter.Process

exportSucceeded = True

Set node = parser.Document

Set nodelist = node.GetElementsByTagName(“urllink”)

If nodelist.NumberOfEntries <> 0 Then

  For i = 1 To nodelist.NumberOfEntries

     Set linknode = nodelist.GetItem(i)

     strLink = linknode.GetAttribute("href") 'retrieve text from the url

     For x=0 To Ubound(oldLinks) 'compare paths to replace to retrieved link and see if we encounter a link to replace

        If Instr(strLink, oldLinks(x)) <> 0 Then

           intCount = intCount + 1

           newLink = ReplaceSubstring(strLink, oldLinks(x), newLinks(x))

           boolLogIt = True

        End If

     Next

  Next

End If

With this code I can already detect if and which urllinks schould be changed. But it’s the import back to the Notesdocument that doesn’t succeed.

Who can help me?

Thanks in advance!

Subject: RE: change links using NotesDXLExporter and NotesDXLImporter

But, Elke, it IS just text in a document once you’ve converted to DXL. Everything is – just like HTML. However, there are limits to what you can do with extremely long strings, as Chris noted.

If you want to use the NotesDOMParser and DOM methods to do the work, then you need to set up your pipeline correctly (you are not pipelining to the NotesDXLImporter at all), and need to call Serialize against the parser’s output. You should also move your DOM code into a subroutine that can be called on the PostDOMParse event of the NotesDOMParser object. The examples (not just the main pages) in Designer help are very good for these objects/methods.