我有一个XmlObject(org.apache.xmlbeans.XmlObject)obj.
XmlObject obj;
...
obj.toString(); //<xml-fragment>n2</xml-fragement>
// content ="n2"
String content = obj.toString().substring(14, obj.length() - 15)
Run Code Online (Sandbox Code Playgroud)
在内容中存储"n2"的正确方法是什么?
从SimpleValue的javadoc - "所有XmlObject实现都可以强制转换为SimpleValue"
所以正确的方法是:
//to get the string value
((SimpleValue)obj).getStringValue();
//to set the string value
((SimpleValue)obj).setStringValue("n2");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6504 次 |
| 最近记录: |