0
ich ein xml/mathml Fragment in Zeichenfolge habe wie <msup><mn>2</mn><mn>6</mn></msup><mo>+</mo><msup><mn>2</mn><mn>7</mn></msup>
hinzufügen XML String als Knoten zu vorhandenen XML
ich einen vorhandenen XML-Knoten mit dieser Zeichenfolge ersetzt werden soll. Ich
versuchtDocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuild = docFactory.newDocumentBuilder();
Document doc = docBuild.parse(is); //is ==> Inputstream
XPath xpath = XPathFactory.newInstance().newXPath();
xpath.setNamespaceContext(new Namespace());
XPathExpression expr = xpath.compile(xPath); //xPath ==>XPath of parent node where the above is to be appended
Node node = (Node) expr.evaluate(doc, XPathConstants.NODE);
if (node.getChildNodes().item(0).getNodeName().equals("mml:math")) {
node.removeChild((node.getChildNodes().item(0)));
Element s= doc.createElement("mml:math");
s.setNodeValue("<msup><mn>2</mn><mn>6</mn></msup><mo>+</mo><msup><mn>2</mn><mn>7</mn></msup>");
node.appendChild(s);
}
Was ist mit dem Code passiert, den Sie ausprobiert haben? –
XML wurde nicht aktualisiert .... –
Wenn Sie Quelle xml, wäre es einfach, Ihre Frage zu beantworten – ssanrao