The inner text is a bit tricky, since Simple does not allow text and (child-) elements together. But please see my answer here, how you can solve this:
The key part there is the QuestionConvert
class.
Question
How to xml-parsing tag+text in tag (simple-framework) http://simple.sourceforge.net/resources.php
I want to print this
: xliffTestModel=XliffTestModel [attname=hours, g=%1$s, text=hours!!]
I can't parse "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>
Here is my code.
[Model]
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 + "]";
}
}
[Main Code]
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);
Solution
The inner text is a bit tricky, since Simple does not allow text and (child-) elements together. But please see my answer here, how you can solve this:
The key part there is the QuestionConvert
class.