• Post Reply Bookmark Topic Watch Topic
  • New Topic

Best way to map between 'code syntax' and xml?  RSS feed

 
Bjorn Svensson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all,

I have a system thatin general speaks xml, using jaxb to create objects from xml.
The xml is used for boolean expressions such as below

<and> <equals param="yyy" val=123/> <greater param="xxx" val=456 /> </and>

Its easy using my objects to create a 'code/text' output of that to something like:
'yyy=123 && xxx>456'

What I like to do is the opposite, to be able to edit the expressions using the 'code' form.

There are plenty of ways to solve this, I'm curios what the best path is, should I go with
stuff like antlr / javacc or comething completely different?
 
Carey Brown
Saloon Keeper
Posts: 3328
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the example you gave, I might be tempted to write a recursive descent parser for it directly. If the complexity of the expressions is much bigger then I'd be looking into Antlr or Javacc.

I do find that your XML is not generic enough. Who's to say that an 'equals' tag will always have a 'param' and a 'value'. Why not two params, why not a param and an expression?

<and><equals><param>yyy</param><value>123</value></equals><greater><param>xxx</param><value>456</value></greater></and>

I'd be interested in hearing from others who have Antlr or Javacc experience.

Carey
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!