0
如何XML的解析標籤+文本標籤(簡單的框架)http://simple.sourceforge.net/resources.php如何XML的解析標籤+文本標籤(簡單的框架)
我想打印
: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);
非常感謝! – user3167460