Parsing:
I don’t know Objective-C/Cocoa, and learning ASObjC would take some time that I don’t have right now.
You don't have to know Objective-C/Cocoa, and the basics of ASObjC are pretty simple.
Writing:
However in my current project, I need to write XML. I like the method of having applescript records translated to XML – something like the solution for writing Json that you provided in Macscripter forums, or the way XML Tools does the job.
Do you mean something like this:
use framework "Foundation"
on makeXMLDocWithRecord:theRecord
-- make root element
set rootElement to current application's NSXMLNode's elementWithName:"dict"
-- make XML document
set theXMLDocument to current application's NSXMLDocument's alloc()'s initWithRootElement:rootElement
theXMLDocument's setDocumentContentKind:(current application's NSXMLDocumentXMLKind)
theXMLDocument's setStandalone:true
theXMLDocument's setCharacterEncoding:"UTF-8"
-- make dictionary from record
set anNSDictionary to current application's NSDictionary's dictionaryWithDictionary:theRecord
-- add children to root element
set theKeys to anNSDictionary's allKeys() as list
repeat with i from 1 to count of theKeys
set theKey to item i of theKeys
set newElement to (current application's NSXMLNode's elementWithName:"key" stringValue:theKey)
(rootElement's addChild:newElement)
set newElement to (current application's NSXMLNode's elementWithName:"string" stringValue:(anNSDictionary's valueForKey:theKey))
(rootElement's addChild:newElement)
end repeat
-- return as string with whatever formatting options you want
return (theXMLDocument's XMLStringWithOptions:(current application's NSXMLNodePrettyPrint)) as text
end makeXMLDocWithRecord:
set theRecord to {firstName:"Saga", lastName:"Norén", city:"Malmö"}
its makeXMLDocWithRecord:theRecord