Am 07.11.2011 um 08:07 schrieb Steffen Märcker:
Hi Norbert,
thanks a lot for your extensive reply.
I don't know the simpleXO stuff.
If you like, please load it from Cincom public repository and play a bit. The Pharo port will take some additional time.
Cdata is associated with primitive types. But then in your "width" mapping you map an element to a native type. That makes only sense if this a convenient way of writing it.
My idea behind the name 'cdata' was to hint that these types use the string-value (see XPath) of an XML node to build objects. I had in mind that these types should not be restricted to simple (schema) types. E.g. a use case requires to extract the text from an html paragraph element:
<p>This is an <em>emphasized text</em>.</p> <div><p>And this a text as well.</p></div>
"Consider the mapping"
doc := (builder defineElement: 'Document' class: 'OrderedCollection'). doc mapPath: (RootStep // 'p') toType: 'Paragraph') setter: #add:. (builder defineCData: 'Paragraph' class: 'Text') constructor: #fromString:.
"Which gives us" (OrderedCollection new) add: (Text fromString: 'This is an emph ...'); add: (Text fromString: 'And this is ...')
What's your opinion on that example? Are 'element' and 'cdata' still misleading?
Well, sort of. I think I'm starting to get it. defineElement: and defineCData: are meant that you get the content _from_ the element or cdata? So defineCData: extracts the text from the Node?
From that point of view I think that Cdata is the wrong name anyway. CData and PCData are mainly present in the textual form of XML. After the XML is parsed you usually consider both as text. In PCData <em> would lead to an element while in CData it will be the text "<em>". So I think you basically have Element and Text. If the methods would be a little bit more intention revealing even a person like me would get it :) I mean the builder "builds" "your type" from "another (XML) type".
Did you consider instead of having a constructor: setter to provide a block instead. Usually this adds a little complexity but opens a whole set of possible use cases.
I am not sure whether 'simple' and 'complex' reflect the nature of the types well, since a cdata type my have it's own mappings as well:
text := (builder defineCData: 'Paragraph' class: 'Text') constructor: #fromString:. (text mapPath: (AttributeAxis ? 'id') toType: 'String') key: 'p-ids'.
This example uses the value of @id as key to allow referencing the created object elsewhere. A more sophisticated example could use a parser that parses a given string-value and the fields of the result are set by SimpleXO later.
That sounds interesting but I don't get the example. Can you elaborate on this? Or provide a more concrete example.
Norbert
I am looking forward to your (and anyone else's) thoughts!
Regards, Steffen _______________________________________________ Moose-dev mailing list Moose-dev@iam.unibe.ch https://www.iam.unibe.ch/mailman/listinfo/moose-dev