Hello,
I have a very simple agent that presents a Domino data as XML. The agent works very well when the fields I am sending to XML don’t contain any “special characters”. For example if the field contains “&”, the following is returned:
Whitespace is not allowed at this location. Error processing resource 'http://unmee-mail-02/telephone/ciphone.nsf/createXML…
2Ic & Soo
-------------------^
If I remove “&” sign and replace it with “and” the agent works perfectly. This is the code I am using:
Print “Content-type: text/xml”
Print “”
While Not ( doc Is Nothing )
Print “”
Print " “+doc.FirstName(0)+”"
Print " "
Set doc = view.GetNextDocument( doc )
Wend
Print “”
Is there a way to pass the data as it is to XML, or otherwise to “clean up” data before passing to XML?
Any idea is higly appreciated
Thanks,
Dali
Subject: LotusScript agent to XML (corrected)
Here’s a routine that replaces entity references. Make sure to only call the function oncer per target string. You can replace the “lite” error handling with your own.
hth,
dgg
Function convertEntityRef(pstrValu As String) As Boolean
On Error Goto errorHandler
Const AMPERSAND = "&"
Const APOSTROPHE = "'"
Const DBL_QUOTES = """
Const GT = ">"
Const LT = "<"
convertEntityRef = False
pstrValu$ = Replace(pstrValu$, {&}, AMPERSAND)
pstrValu$ = Replace(pstrValu$, {'}, APOSTROPHE)
pstrValu$ = Replace(pstrValu$, {<}, LT)
pstrValu$ = Replace(pstrValu$, {>}, GT)
pstrValu$ = Replace(pstrValu$, {"}, DBL_QUOTES)
convertEntityRef = True
functionExit:
Exit Function
errorHandler:
Msgbox "Error " & Err & ": " & Error & " encountered at line " & Erl & " of " & Getthreadinfo(1) & ".", , "Error encountered . . ."
Print "Error " & Err & ": " & Error & " encountered at line " & Erl & " . . ."
Resume functionExit
End Function
Subject: RE: LotusScript agent to XML
Dallas,
You are aware that your code is double-escaping the entities?
The original poster should use the following constants:
Const AMPERSAND = “&”
Const APOSTROPHE = “'”
Const DBL_QUOTES = “"”
Const GT = “>”
Const LT = “<”
cheers,
Bram
Subject: RE: LotusScript agent to XML
Dooh . . . I had copied the code from the searchDomino tip I had posted a while back. That’s how the source code is rendered when viewing it in FireFox (works fine in IE). I notified the editor, but it was never fixed. I corrected it in my response though.thanks,
dgg
Subject: LotusScript agent to XML
You should read up on XML because the ampersand (&) IS a special character.
You should replace the following characters in XML:
& → &
< → <
→ >
’ → '
" → "
As long as the you’re using the correct encoding in the XML header, it doesn’t mind any other ‘special’ (non-ascii) characters.
cheers,
Bram