Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract information from XmlObject in JAVA without using toString()?

Tags:

java

xml

xmlbeans

I have an 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) 

What is the right way to store "n2" in content?

like image 924
M.C. Avatar asked Apr 09 '26 01:04

M.C.


1 Answers

From the javadoc for SimpleValue - "All XmlObject implementations can be coerced to SimpleValue"

So the correct approach would be:

//to get the string value
((SimpleValue)obj).getStringValue();
//to set the string value
((SimpleValue)obj).setStringValue("n2");
like image 139
Boris the Spider Avatar answered Apr 11 '26 15:04

Boris the Spider



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!