是否可以使用Haml生成原始的XML? [英] Is it possible to generate plain-old XML using Haml?

查看:75
本文介绍了是否可以使用Haml生成原始的XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在开发一款软件,需要生成自定义XML文件以发送回客户端应用程序。 Ruby / Rails世界上当前用于生成XML文件的解决方案充其量是缓慢的。使用生成器或事件Nokogiri,虽然语法不错,而且是可维护的解决方案,但它们会浪费大量时间和处理资源。

I've been working on a piece of software where I need to generate a custom XML file to send back to a client application. The current solutions on Ruby/Rails world for generating XML files are slow, at best. Using builder or event Nokogiri, while have a nice syntax and are maintainable solutions, they consume too much time and processing.

我肯定可以去ERB,这提供了一个很好的解决方案

I definetly could go to ERB, which provides a good speed at the expense of building the whole XML by hand.

HAML 是一个很棒的工具,语法简洁,直观,而且速度很快。但是我正在努力使用它来构建纯XML文件。

HAML is a great tool, have a nice and straight-forward syntax and is fairly fast. But I'm struggling to build pure XML files using it. Which makes me wonder, is it possible at all?

是否有人指向一些代码或文档来显示如何执行此操作,并从中构建完整的有效XML?

Does any one have some pointers to some code or docs showing how to do this, build a full, valid XML from HAML?

推荐答案

在HAML中执行XML很容易,只需从模板开始:

Doing XML in HAML is easy, just start off your template with:

!!! XML

产生

<?xml version='1.0' encoding='utf-8' ?>

然后就像@beanish前面说的那样,您组成自己的标签:

Then as @beanish said earlier, you "make up your own tags":

%test
  %test2 hello
  %item{:name => "blah"}

得到

<test>
  <test2>hello</test2>
  <item name='blah'></item>
</test>

更多:
http://haml.info/docs/yardoc/file.REFERENCE.html#doctype_

这篇关于是否可以使用Haml生成原始的XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆