我可以将文件大小添加到 Builder XML 输出吗
我正在开发一个 Ruby on Rails 应用程序,该应用程序使用构建器模板生成大型 XML 文档,但我遇到了一些障碍。
XML 输出必须有一个包含文件大小(以字节为单位)的字段。我认为我基本上需要使用填充 http 响应中“Content-Length”标头的值,但更新标记的值显然会改变文件大小。
输出应如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<metadata>
<filesize>FILESIZE</filesize>
<filename>FILENAME.xml</filename>
</metadata>
<data>
.
.
.
</data>
</dataset>
IsAdding the file size in an XML tag possible using a builder template?如果没有,我可以使用某种方法来达到所需的结果吗?
I'm working on a ruby on rails app that generates a large XML document using a builder template, but I've hit a bit of a stumbling point.
The XML output must have a field that contains the file size in bytes. I think that I'll basically need to use the value that would populate the "Content-Length" header in the http response, but updating the value of the tag will obviously change the file size.
The output should looks something like this:
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<metadata>
<filesize>FILESIZE</filesize>
<filename>FILENAME.xml</filename>
</metadata>
<data>
.
.
.
</data>
</dataset>
Is adding the file size in an XML tag possible using a builder template? If not, is there some method that I could use to achieve the required result?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢 Garrett,我能够想出以下(丑陋的)解决方案,它确实需要改进,但它确实有效:
Thanks to Garrett I was able to come up with the following (ugly) solution, it definitely needs improvement, but it does work: