Re: [DoubleType-dev-en] Question Relaxer
Status: Alpha
Brought to you by:
eed3si9n
|
From: e.e <eed...@us...> - 2005-01-12 09:45:23
|
Hi Nemesis, > I think i kinda understand the most of it, but > I can't seem to understand what the Relaxer-part is all about. > I can find it's a tool to put XML-code into java-code, > and so it generates the whole xml-package, but i don't understand the > meaning of it within the program... You've mentioned you wanted to know the thinking process behind DoubleType so I'll try to explain that. When I started designing the program I knew XML would be used. XML is simple but deep. From simple point of view, XML is just HTML look-alike. Bunch of tags. More modern way of looking as XML is XML as a meta-language: a language that lets you define your own language. For example, we can define a language where you have a <root> tag, and within the <root> tag, you have zero or more <employee> tags, and within each <employee> tag you have a <lastname> tag. A sample document in the language would look like this: <root> <employee><lastname>Smith</lastname></employee> <employee><lastname>Brown</lastname></employee> </root> It would be useful if we can describe the grammer in some way. A language that let's you describe the grammer of XML-derived language is called schema language. The most standard schema language is W3C XML Schema (.xsd file) but it is too difficult for human to use it. As an alternative schema language, there is RELAX NG. There are two notations for RELAX NG, the original XML syntax (.rng) and compact syntax (.rnc). I personally prefer compact syntax now, but for DoubleType XML syntax is used. - http://www.oasis-open.org/committees/relax-ng/tutorial.html - http://relaxng.org/compact-tutorial-20030326.html Let's describe our sample language using RELAX NG compact syntax: element root { element employee { element lastname { text } }* } One of the benefit to define the grammar of your language using using a schema language is that there are tools that lets you parse the XML document into object automatically. Without those tools, you would have to manually parse/generate XML documents, which people used to do. Since we defined <root> tag and <employee> tag, it would be convenient if a tool can generate root class and employee class so you can just use it in code like m_root.getEmployee(0).lastname = "smith"; This idea of mapping XML document and object is called XML data binding. Relaxer is a XML data binding tool that uses RELAX NG as input. # There are other tools that does XML data binding. # Castor is more popular, I think. Other platforms have their own stuff. X-prefixed classes in org.doubletype.ossa.xml package generated by Relaxer. I put anything that needs to be saved into the file into my glyph language. This saves a lot of work because I only need to define it once in the schema and it would be in both Java object and XML. It's kind of getting long, so I'll send it here and continue. Thanks, e.e |