I'm having some fun today thinking about how to get the XML out of HiveMind.
I've long defended the use of XML inside Tapestry (and HiveMind), because it was a convienent, standard way to store hierarchical data. But it is hard to type, hard to read, hard to edit and has some challenges to parse. So I'm thinking about other options.
So ... I still want elements and attributes and nesting, though I don't actually care about nested character data. Nested character data is for documents, not hierarchical data files (despite the fact that Sun's DTDs never use attributes, just character data).
What I have so far (a couple of hours hacking around) is something small and simple. An element is a name. It may be followed by a list of attributes inside parens. An element terminates with a semicolon, or uses curly braces to denote nested elements. Attribute values don't have to be quoted if they look like identifiers, or are numeric literals. Looks something like:
module (id=foo.bar.baz version="1.0.0") { service-point (id=Startup interface=java.lang.Runnable) { create-object (class=foo.bar.baz.StartupImpl); } }
Of course, use of whitespace is totally at your discretion. For comparison, the equivalent XML document:
<?xml version="1.0"> <module id="foo.bar.baz" version="1.0.0"> <service-point id="Startup" interface="java.lang.Runnable"> <create-object class="foo.bar.baz.StartupImpl"/> </service-point> </module>
This is a chance for me to look at JavaCC, a common tool for writing language recognizers and parsers. Good experience in and of itself.
On the other hand, it may be smarter to follow others and simply implement the similarily themed YAML -- YAML Aint Markup Language. When I gave a HiveMind presentation a few month's back at a local Java user's group, I was asked about YAML then, and had a vague understanding of it. YAML has a few more features, better mimicing most (if not all) of XML.
I think the YAML version would be:
--- #YAML:1.0 module: id: foo.bar.baz version: 1.0.0 - service-point: id: Startup interface: java.lang.Runnable - create-object: class: foo.bar.baz.StartupImpl
For either of these two formats, it would be straight-forward to create a filter that produces equivalent XML.
No comments:
Post a Comment
Please note that this is not a support forum for Tapestry. Requests for help will be deleted. Please subscribe to the Tapestry user mailing list if you are in need of support, or contact me directly for professional (for pay) support.
Spammers: Don't bother. I delete your comments and it's a waste of time for both of us. 垃圾邮件发送者:不要打扰。我删除您的评论和它的时间对我们双方的浪费