如何在标记中使用xml解析标记+文本(简单框架)http://simple.sourceforge.net/resources.php
我想打印这个 :xliffTestModel = XliffTestModel [attname = hours,g =%1 $ s,text = hours !!]
我无法解析“小时!!”
[XML]
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="hours">
<xliff:g id="hours">%1$s</xliff:g> hours!!
</string>
</resources>
这是我的代码。
[模型]
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;
@Root(name = "resources")
public class XMXliffStringModel {
@Element(name = "string")
public XliffTestModel xliffTestModel;
@Override
public String toString() {
return "XMXliffStringModel [xliffTestModel=" + xliffTestModel + "]";
}
}
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Namespace;
import org.simpleframework.xml.Root;
@Root(name = "string")
public class XliffTestModel {
@Attribute(required = false, name = "name")
public String attname = "";
@Namespace(prefix = "xliff")
@Element(required = false, name = "g")
public String g;
@Override
public String toString() {
return "XliffTestModel [attname=" + attname + ", g=" + g + "]";
}
}
[主要代码]
XMXliffStringModel xmXliffStringModel = new XMXliffStringModel();
String path = "C:/Users/SEC/Desktop/strings.xml";
Serializer serializer = new Persister();
try {
xmXliffStringModel = serializer.read(xmXliffStringModel.getClass(), new File(path));
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(xmXliffStringModel);
答案 0 :(得分:0)
内部文本有点棘手,因为Simple不允许将text和(child-)元素放在一起。但请在此处查看我的答案,如何解决这个问题:
关键部分是QuestionConvert
类。