Вопрос

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?

Это было полезно?

Решение

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");

Другие советы

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top