StringTemplate无效字符'<'阅读XML模板时 [英] StringTemplate invalid character '<' when reading XML Template
本文介绍了StringTemplate无效字符'<'阅读XML模板时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<?xml version = ? 1.0 >
我读过这样的文件:
STGroup group = new STGroupDir(templates);
ST st = group.getInstanceOf(report);
st.add(分析,ana);
String result = st.render();
System.out.println(result);
结果是几条错误信息:
report.st 1:1:无效字符'<'
report.st 1:1:无效字符'?'
report.st 1:19 :无效字符'?'
report.st 1:20:无效字符'>'
report.st 1:2:输入'xml'没有可行的替代方案
我看过其他人阅读也使用标签的HTML tempaltes。那么我在做什么错了?
解决方案
好吧,我忽略了你需要在不同的snytax中指定模板。 Allthough这从我用过的例子中并不明显:
我的工作模板现在看起来不同:
报告(分析):: =<<
<?xml version =1.0?>
>>
另外我还更改了delimeters:
STGroup group = new STGroupDir(templates,'$','$');
I am trying to create a simple XML-Template which so far only consists of:
<?xml version="1.0"?>
I read the file like this:
STGroup group = new STGroupDir("templates");
ST st = group.getInstanceOf("report");
st.add("analysis", ana);
String result = st.render();
System.out.println(result);
And the result is several error messages:
report.st 1:1: invalid character '<'
report.st 1:1: invalid character '?'
report.st 1:19: invalid character '?'
report.st 1:20: invalid character '>'
report.st 1:2: no viable alternative at input 'xml'
I have seen other people reading HTML tempaltes that also use tags. So what am I doing wrong?
解决方案
Okay it seems I overlooked that you need to specify templates in a different snytax. Allthough this was not obvious from the examples I used:
My working template looks different now:
report (analysis) ::= <<
<?xml version="1.0"?>
>>
In addition I also changed the delimeters:
STGroup group = new STGroupDir("templates",'$','$');
这篇关于StringTemplate无效字符'<'阅读XML模板时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文