我想使用 XQuery 从我的 XML 文档生成 Java 源代码,例如:
<configuration package="my.package.name">
<property>
<name>First</name>
<value>0</value>
<description>First description</description>
</property>
<property>
<name>Second</name>
<value>2</value>
<description>Second description</description>
</property>
...
应该生成:
package my.package.name;
class MyClass {
// First description
private String first;
// Second description
private String second;
}
我试图这样开始:
xquery version "1.0";
"package "+$doc/@package
"class "+$doc/@classname
{
for $property in $doc//property
return {
"private String "+$property/name::text()
}
}
语法显然不正确,我想知道它是否可行。谢谢!