OK, I’m parsing a document and looking for a particular field. When I find my field ( they are rich text fields with simple notes tables in them ( 2cols, 1 to many rows) ), I start looking for certain elements such as the table row and table column elements.
I export a field to DXL, then I parse it using SAXParser. On the following three events…
On Event SAX_StartElement From saxParser Call mySAXStartElement
On Event SAX_Characters From saxParser Call mySAXCharacters
On Event SAX_EndElement From saxParser Call mySAXEndElement
I parse out the data and can find my field that I am looking for.
Everything works beautifully when the rich text field that I am looking for is in edit mode. When I change the field to a computed field and have it simply compute it itself, then the field ( when parsed) will have differing elements. When the field is computed, the xml does NOT contain the tablerow or tablecol elements. Strange!!
When the field is in edit mode, the exact same rich text field, with the exact same 2 col, 2 row table WILL contain the tablerow or tablecol elements.
Why is this?
Should I have to write differing code to parse a field depending upon if it is in read or edit mode?
Is there an easier way to do this that I am missing?
All help is appreciated! Thanks - jamie
Code sames are below and then below that is my print lines of parsing field in edit mode versus read mode. You can see the difference in elements.
'// Set class object for richtext details if available…
Set DDTableData = New RTtable2Array( nsess )
Call DDTableData.SetDXLInsOuts( ndocCurrent, rtitemRptDetails )
DDTableData.SetTargetFieldName = "Priority" ' name of rt field we want to parse.
DDTableData.blnLogProcess = True
Call DDTableData.Process
…………………………………………………
Public Sub New (pnsess As NotesSession )
' Set variable defaults...
Redim Me.MyArray(0)
Me.blnTableCellStart = False
Me.blnDataIn2ndCol = False
Me.intTableRowCtr = 0
Me.intTableColCtr = 0
Me.strTableCell = ""
Me.strTargetFieldName = "Details" ' Default rich text field name for Daily Data form.
Me.blnGotRightField = False
Me.blnLogProcess = False
' Set in base class so comment this line out.
' Set Me.nsess = pnsess
' Initialize SAX parser & exporter object...
Set Me.saxParser = pnsess.CreateSAXParser()
Set Me.exporter = pnsess.CreateDXLExporter()
' Set event handling...
'// NOTE: ( notes from dgg - thks )
'// For whatever reason, using "Me" when binding these events doesn't work so I used
'// different names for the subroutines to prevent any problems/confusion with names
'// of external modules.
On Event SAX_StartElement From saxParser Call mySAXStartElement
On Event SAX_Characters From saxParser Call mySAXCharacters
On Event SAX_EndElement From saxParser Call mySAXEndElement
End Sub
'## ==== SetDXLInsOuts ==== ##
Public Sub SetDXLInsOuts( pndocTarget As notesdocument, prtitmField As notesrichtextitem)
' Convert the document's Data to DXL and then parse through it dumping
' to richtextitem ( this part doesn't work).
Call Me.exporter.SetInput( pndocTarget )
Call Me.saxParser.SetInput( Me.exporter ) ' pipeline to saxParser...
Call Me.saxParser.SetOutput( prtitmField )
End Sub
'## ==== Process ==== ##
Public Sub Process
' Process the richtextitem to dxl and then parse it.
Me.exporter.Process
End Sub
'## ==== SAXStartElement ==== ##
Public Sub mySAXStartElement (Source As Notessaxparser, Byval ElementName As String, Attributes As NotesSaxAttributeList)
On Error Goto errorHandler
Dim i As Integer
Dim attrname As String
If Me.blnLogProcess = True Then Print "Open " & ElementName
Select Case Lcase(ElementName)
Case "item"
If Attributes.Length > 0 Then
For i = 1 To Attributes.Length
attrname = Attributes.GetName(i)
If Me.blnLogProcess = True Then Print "Does " & Lcase( Attributes.GetValue(attrname) ) & " = " & Lcase( Me.strTargetFieldName ) & " ?"
If Lcase( Attributes.GetValue(attrname) ) = Lcase( Me.strTargetFieldName ) Then
If Me.blnLogProcess = True Then Print "Yes!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Found field!"
Me.blnGotRightField = True
If Me.blnLogProcess = True Then Print "blnGotRightField = " & Me.blnGotRightField
If Me.blnLogProcess = True Then Print "Attribute "+attrname+" = " +Attributes.GetValue(attrname)+", type = "+Attributes.GetType(attrname)
End If
Next
End If
Case "tablerow"
If Me.blnGotRightField = True Then
Me.intTableRowCtr = Me.intTableRowCtr + 1
Me.intTableColCtr = 0
'Print "Open " & ElementName
Redim Me.HolderArray( 0 ) As Variant
Redim Preserve Me.MyArray( Me.intTableRowCtr - 1 ) As Variant
End If
Case "tablecell"
If Me.blnGotRightField = True Then
Me.blnTableCellStart = True
Me.intTableColCtr = Me.intTableColCtr + 1
Redim Preserve Me.HolderArray( Me.intTableColCtr - 1 ) As Variant
'Print "Open " & ElementName
End If
End Select
exitThis:
Exit Sub
'// ERROR HANDLING
errorHandler:
Dim ndbCurrent As notesdatabase
Set ndbCurrent = Me.nsess.currentdatabase
If ndbCurrent.server = "" Then
Call UseMailLog("OpenLog@Anderson")
End If
Messagebox LogError(),, "Error:"
Resume exitThis
End Sub
Public Sub mySAXCharacters (Source As Notessaxparser, Byval Characters As String, Count As Long)
On Error Goto errorHandler
If Me.blnLogProcess = True Then Print "Char Value = " & Characters
If Me.blnGotRightField = True Then ' make sure we are getting characters from the field that we are interested in.
'Print "Value = " & Characters
If Trim( Characters ) >< "" Then
If Characters <> Chr(10) Then
If Me.blnTableCellStart = True Then
If Me.strTableCell = "" Then
Me.strTableCell = " " + Trim( Characters )
Else
Me.strTableCell = Me.strTableCell + Chr(10) + " " + Trim( Characters )
End If
'Print "Value = " & Characters
End If
End If
End If
End If
exitThis:
Exit Sub
'// ERROR HANDLING
errorHandler:
Dim ndbCurrent As notesdatabase
Set ndbCurrent = Me.nsess.currentdatabase
If ndbCurrent.server = "" Then
Call UseMailLog("OpenLog@Anderson")
End If
Messagebox LogError(),, "Error:"
Resume exitThis
End Sub
'## ==== SAXEndElement ==== ##
Public Sub mySAXEndElement (Source As Notessaxparser, Byval ElementName As String)
On Error Goto errorHandler
If Me.blnLogProcess = True Then Print "Close " & ElementName
Select Case Lcase(ElementName)
Case "item"
' close the item out after ite ends...
If Me.blnGotRightField = True Then
If Me.blnLogProcess = True Then Print "Setting blnGotRightField = False................................."
Me.blnGotRightField = False
End If
Case "tablecell"
If Me.blnGotRightField = True Then
Me.blnTableCellStart = False
'// Put data in our HolderArray...
Me.HolderArray( Ubound(Me.HolderArray) ) = Me.strTableCell
If Me.intTableColCtr > 1 Then
If Me.strTableCell >< "" Then
Me.blnDataIn2ndCol = True
End If
'// End of cell so set strTableCell to nothing...
Me.strTableCell = ""
'Print "Close " & ElementName
End If
Case "tablerow"
If Me.blnGotRightField = True Then
' Put entire row of table cells in first element of array.
Me.MyArray( Me.intTableRowCtr - 1 ) = Me.HolderArray()
'Print "Close " & ElementName
End If
End Select
exitThis:
Exit Sub
'// ERROR HANDLING
errorHandler:
Dim ndbCurrent As notesdatabase
Set ndbCurrent = Me.nsess.currentdatabase
If ndbCurrent.server = "" Then
Call UseMailLog("OpenLog@Anderson")
End If
Messagebox LogError(),, "Error:"
Resume exitThis
End Sub
'## ==== Process ==== ##
Public Sub Process
' Process the richtextitem to dxl and then parse it.
Me.exporter.Process
End Sub
Priority Rich Text field in Edit mode
Does priority = priority ?
Yes!!! Found field!
blnGotRightField = True
Attribute name = Priority, type = CDATA
Does false = priority ?
Does false = priority ?
Does false = priority ?
Does false = priority ?
Does false = priority ?
Does false = priority ?
Does false = priority ?
Open richtext
Open pardef
Close pardef
Open par
Open run
Open font
Close font
Char Value = Read only.
Close run
Close par
Open table
Open tablecolumn
Close tablecolumn
Open tablecolumn
Close tablecolumn
Open tablerow
Open tablecell
Open pardef
Close pardef
Open par
Open run
Open font
Close font
Char Value = Do your work
Close run
Close par
Close tablecell
Open tablecell
Open pardef
Close pardef
Open par
Open run
Open font
Close font
Char Value = Make sure all your work is done before you leave the store today
Close run
Close par
Close tablecell
Close tablerow
Open tablerow
Open tablecell
Open par
Open run
Open font
Close font
Char Value = All Regions look good
Close run
Close par
Close tablecell
Open tablecell
Open par
Open run
Open font
Close font
Char Value = Good job guys - keep up the hard work and keep your eyes on the goal!
Close run
Close par
Close tablecell
Close tablerow
Close table
Open par
Open run
Open font
Close font
Close run
Close par
Close richtext
Close item
Setting blnGotRightField = False…
Priority Rich Text Field in Computed Mode ( Computed to itself ‘Priority’)
Open item
Does priority = priority ?
Yes!!! Found field!
blnGotRightField = True
Attribute name = Priority, type = CDATA
Does false = priority ?
Does false = priority ?
Does false = priority ?
Does false = priority ?
Does false = priority ?
Does false = priority ?
Does false = priority ?
Open richtext
Open par
Open run
Open font
Close font
Char Value = Read only.
Close run
Close par
Open pardef
Close pardef
Open par
Open run
Open font
Close font
Char Value = Do your work
Close run
Close par
Open pardef
Close pardef
Open par
Open run
Open font
Close font
Char Value = Make sure all your work is done before you leave the store today
Close run
Close par
Open par
Open run
Open font
Close font
Char Value = All Regions look good
Close run
Close par
Open par
Open run
Open font
Close font
Char Value = Good job guys - keep up the hard work and keep your eyes on the goal!
Close run
Close par
Open pardef
Close pardef
Open par
Open run
Open font
Close font
Close run
Close par
Close richtext
Close item
Setting blnGotRightField = False…