raz3r
raz3r

Reputation: 3131

How to read a RichText field?

I have an agent which is supposed to show a Notes DB as XML. I successfully retrieved all the fields but the RichText one. This is a code snippet:

Set session = New NotesSession
Set doc = session.DocumentContext
Set db = Session.CurrentDatabase
Set view = db.getview("myView")
Set doc = view.GetFirstDocument()

While Not(doc Is Nothing)
    Print "<job>"
    Print "<id>" & doc.id(0) & "</id>" ' Works fine since ID is a normal field
    Print "<text>" & doc.text(0) & "</text>" ' Does not work at all 
    Print "</job>"
    Set doc = view.GetNextDocument(doc)
Wend

If I use doc.text instead of doc.text(0) it only writes the first two words of the whole text. I suppose I have to cicle through the entire text but since I am new to Lotus Script I have no idea how to do it. Thank you guys.

EDIT: It turned out that Simon's answer is correct. The problem regards encoding as far as I can tell, if I remove the following Print:

Print |Content-Type:text/xml| & Chr$(13)

Everything works fine. I guess I need to define encoding in the header...

EDIT: I now use this Print instead:

Print "<text><![CDATA[" & rtitem.getUnformattedText() & "]]></text>"

However when I call the agent from the Browser it still broke at that print as it is ignoring the CDATA.

Upvotes: 1

Views: 4161

Answers (1)

Simon O&#39;Doherty
Simon O&#39;Doherty

Reputation: 9349

Don't use the dot notation. To get the Richtext field you will need to use the getFirstItem() method call and link it to a NotesRichTextItem object. After that you should be able to convert it to text using the getUnformattedText() method.

Dim rtitem As NotesRichTextItem
...
rtitem = doc.getFirstItem("text")

Print "<text>" & rtitem.getUnformattedText() & "</text>" 

Of course you may need to parse that text to prevent non standard characters in the XML, or wrap it in a CDATA block.

Upvotes: 1

Related Questions