Most of my XML experience is parsing existing documents and not creating them, so I’m stuck on what I thought would be a simple task, writing string data to an element.
Here’s the problematic code. It’s just a snippet, but all variables are correct when the code gets here. When it runs the last line, where I’m trying to write a 700 byte Security Scoped Bookmark in a variable named bookmarkData, it crashes the app.
[code]///write the font folder data to the PrefsFile
Dim fontFolderNode As XMLNode
Dim fontBookmarkNode As XMLNode
fontFolderNode = root.AppendChild(xml.CreateElement(“fontFolder”)) 'create the fontFolder element
fontFolderNode.SetAttribute(“URLpath”, f.URLPath) 'create the “URLpath” attribute and set its value
fontFolderNode.SetAttribute(“nativePath”, f.NativePath) 'create the “nativePath” attribute and set its value
fontBookmarkNode = fontFolderNode.AppendChild(xml.CreateElement(“fontBookmark”)) 'create the “fontBookmark” element
fontBookmarkNode.SetAttribute(“theBookmark”, bookmarkData) ''create the “theBookmark” attribute and set its value
[/code]
I’ve tried creating fontBookmarkNode as different types (TEXT_NODE, CDATA_SECTION_NODE) but it either crashes the app or only stores the first 5 to 50 characters of bookmarkData. I hope I’m doing something really stupid because this has me flummoxed. All help greatly appreciated.
How does the crash log look like? Why would you save xml data into an SSB? Why don’t you save the font folder directly into an SSB?
At a guess… sounds like it is binary data, probably has a chr(0) in there somewhere.
Try ENCODEBASE64 on the data before you try to store it here, and then DECODEBASE64 when you retrieve it later
Thanks for your reply, Beatrice. Actually what I’m doing is the reverse, trying to store an SSB string in an XML file. I think Jeff T’s idea sounds like what I’m experiencing since there is binary data in the SSB string.
[quote]@Jeff Tullin At a guess… sounds like it is binary data, probably has a chr(0) in there somewhere.
Try ENCODEBASE64 on the data before you try to store it here, and then DECODEBASE64 when you retrieve it later[/quote]
Thanks Jeff. I think you may be correct. I’ve been avoiding encoding the SSB strings since Apple documentation says encoding them in any way breaks them. But I suspect that doesn’t mean you can’t encode them and then decode them before they’re used. I’ll give it a try and let you know.
I decode/encode the SSB strings, too.
Encoding BASE64 is optional; isnt it ?
I just want to say “Thank You” Beatrix, Emile, and Jeff for your help in solving this problem. Base64 encoding did the trick. Once again, I am indebted to the members of the forum for their patience, generosity and talent. The Xojo community is a special one.
Best to all.