用于 Java 的类 PHP 表示语言
我有一个 Java 应用程序,当前输出 JTree 中对象的 XML。它递归地循环遍历节点,当它找到一个对象时,它会将其打印为带有某些属性的标签,如果它是父节点,它将递归得更深。
我真正想做的是不将输出限制为 XML,而是实现一个演示解释器(例如 PHP),它可以访问我的应用程序中的模型,但以完全自定义的方式显示它。
所以要求是:
- 应用程序需要能够加载模板文件(PHP 或其他文件)
- 然后它应该在内部解释该模板,该模板将访问 Java 模型
- 最后它应该输出将数据和模板组合的结果
I'我很难理解需要什么。我不确定模板引擎是答案,因为我需要通过树进行递归迭代。我不确定我的 PHP 桥是否走在正确的轨道上,因为我似乎需要一些东西来在外部执行 PHP(比如网络浏览器)。
有人对适合此目的的技术有任何建议吗?我正在寻找正确的方向,因为我真的不确定解决这个问题的最佳方法。
我什至正在考虑定义自己的语法和脚本语言,但这感觉就像重新发明轮子。
欢迎所有想法:)
I have a Java application that currently outputs XML of objects in a JTree. It recursively loops through the nodes and when it finds an object it will print it as a tag with some attributes, and if it is a parent node it will recurse deeper.
What I really want to do is not constrain the output to XML but instead implement a presentation interpreter such as PHP which can access the model in my application but display it in a completely customized manner.
So the requirements are:
- The applicaton needs to be able to load a template file (PHP or something else)
- It should then internally interpret this template which will access the Java model
- Finally it should output the result of combining the data and the template
I'm struggling to understand what is required. I'm not sure template engines are the answer because I need recursive iteration through a tree. I'm not sure whether I am on the right track with a PHP bridge because it seems I need something to execute the PHP externally (like a web browser).
Does anybody have any suggestions about what technology would be suitable for this purpose? I'm looking for a shove in the right direction as I'm really not sure the best way to approach this.
I'm even considering defining my own grammar and scripting language but this feels like reinventing the wheel.
All ideas welcome :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您想要的是转换 XML 文档。显而易见的解决方案是 XSLT。
是的,Java 中有许多模板引擎 - Groovy 是最流行的模板引擎之一。毫无疑问,它可以做你想做的事,尽管我不完全确定你如何将它粘合到你的应用程序中 - 它是一个网络框架。值得一看。
It sounds like what you want is to transform an XML document. The obvious solution for that is XSLT.
Yes, there are a number of template engines in Java - Groovy is one of the more popular ones. It can undoubtedly do what you want, though I'm not entirely sure how you'd glue it into your app - it's a web framework. Worth checking out.