Reputation: 1745
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?
Upvotes: 3
Views: 8617
Reputation: 61158
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");
Upvotes: 8
Reputation: 11870
Something like this?
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(new File("input.xml"));
NodeList nodeList = document.getElementsByTagName("Xml-Fragment");
And there you have your nodelist, to take whatever you want from.
Upvotes: 3