2017-04-27 8 views
0
私は、この文字列を持つ既存のXMLノードを交換したい <msup><mn>2</mn><mn>6</mn></msup><mo>+</mo><msup><mn>2</mn><mn>7</mn></msup>

は、既存のXML

のような文字列のXML/MathMLのフラグメントを持って

へのノードとしてXML文字列を追加します。私は私の問題を修正s.setTextContent()を使用し、代わりにs.setNodeValue()を使用しての

DocumentBuilderFactory 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); 
    } 
+0

だから、あなたが試したコードはどうなったのですか? –

+0

XMLが更新されませんでした.... –

+0

あなたがソースXMLを提供すると、あなたの質問 – ssanrao

答えて

0

を試してみました。

関連する問題