“循环"的标准在XML中? [英] standard for "loops" in XML?

查看:59
本文介绍了“循环"的标准在XML中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个用于动画的简单XML文件.我经常遇到这样的情况,我写这样的东西:

I am designing a simple XML file for animations. I often get in the situation, that I write something like this:

<frame>
    <image>./image1.png<image/>
</frame>
<frame>
    <image>./image2.png<image/>
</frame>
<frame>
    <image>./image3.png<image/>
</frame>
...

现在,这当然会很烦人.所以我想这是允许的:

Now, this of course can get annoying. So I would I thought was allowing this:

<frameset min=1 max=5>
    <image>./image#.png<image/>
</frameset>

使#成为计数器变量的占位符. 我想知道的是:已经有一种标准化的方式来做这样的事情吗? 如果人们使用人们已经习惯的方法,这只会使事情变得更容易.

Making # a placeholder for a counter variable. What I am wondering: is there already a standardized way of doing something like this? It just makes things easier if one uses methods people are already used to.

谢谢!

推荐答案

没有通用模型,但是您要寻找的实际上是一个模板解决方案-模板语言加上模板评估引擎,可将模板转换为最终模板通过执行模板中嵌入的代码来实现XML.

There is no universal model, but what you're looking for is essentially a templating solution - a template language plus a template evaluation engine that transforms a template into final XML by executing the code embedded in the template.

因此,对于您的模型,您可以采用您熟悉的任何模板语言.

So, you can take, for a model, ANY templating language you're familiar with.

如果可以使用,最好的方法当然是利用现有的模板引擎解决方案.因此您不必写一个.例如. Java的JSP,Perl的EmbPerl,XSLT等...

The very best approach is of course to leverage an existing templating engine solution if you have access to one; so you don't have to write one. E.g. JSP for Java, EmbPerl for Perl, XSLT etc...

以下是示例EmbPerl模板的外观:

Here's what a sample EmbPerl template would look like:

[$ foreach my $i (1..5) $]
<frame>
    <image>./image[+$i+].png<image/>
</frame>
[$ endforeach $]

许多模板解决方案看起来非常相似,标记略有不同,并且逻辑语法也明显不同(Perl,Java和xxx)

A lot of templating solutions would look very similar, with slightly different markup and obviously different logic syntax (Perl vs. Java vs. xxx)

如果使用自制软件解决方案,模板语言当然可以是XML本身,例如

If you go with homebrew solution, the templating language can of course be XML itself, something like

<frameset min=1 max=5>
    <image part=1 conent_type="constant">./image<image/>
    <image part=2 conent_type="iterator_value"><image/>
    <image part=3 conent_type="constant">.png<image/>
</frameset>

这篇关于“循环"的标准在XML中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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