Thanks Steffen
I am currently working on an XML to object mapping library. I came up with an early version for a project, since I had to map weird/complex/poor XML files. I'm in contact with Stephané Ducasse about a planned Pharo port. He suggested to ask here for your opinions and ideas on this DSL/library.
SimpleXO consists of two parts, a Smalltalk Builder API that constructs a parser object and a non-Smalltalk syntax meant for external binding configuration. This post is on the API.
SimpleXO uses two concepts: types and mappings. A type describes how to construct an object. It is configured with a class, a constructor and mappings. A mapping defines which type a set of nodes is mapped to. The nodes are given by a expression similar to XPath.
Short Example:
<geo id="1"> <rect> <pos x="2" y="3" /> <width>4</width> <height>5</height> </rect> </geo>
"Smalltalk'ish way:" builder := SimpleXOParserBuilder new. (builder defineElement: 'Rect') class: 'Rectangle'; "given as string to postpone resolving" mapPath: ('pos' /@ 'x') toType: 'Int'; mapPath: ('pos' /@ 'y') toType: 'Int'; mapPath: ('width') toType: 'Int'; mapPath: ('height') toType: 'Int'; mapPath: (AnyNodeTest /@ 'id') toType: 'Int'. (builder defineCData: 'Int') class: 'Integer'; constructor: #fromString:. parser := builder buildParser: 'rect'. parser mapNode: xmlNode.
"this gives the following object:" (Rectangle new) x: 2; y: 2; width: 4; height: 5.
Actually we see two kinds of types: element and cdata. The only difference is that elements are constructed using an unary constructor and cdata with a one-argument message that is sent with the string-value of the current node. Of course, SimpleXO supports id resolving, collecting values and tokenizing attribute values. You can find further information on https://wiki.aleturo.com/alpha/simplexo:start
I am really interested in your impressions, questions and ideas so far?
Right now I do not have concrete case but for Moose I would like to have a library that I can use to map xml to moose objects
Regards, Steffen _______________________________________________ Moose-dev mailing list Moose-dev@iam.unibe.ch https://www.iam.unibe.ch/mailman/listinfo/moose-dev