Hello,

Je voudrais modifier un Document grace à XPath... Mais ça ne fonctionne pas... Je ne sais pas si le problème vient de ma chaîne XPath ou de mon code...

Voici mon code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
        DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
        domFactory.setNamespaceAware(true);
        DocumentBuilder builder;
        try {
            builder = domFactory.newDocumentBuilder();
            Document doc = builder.parse(configFilePath);           
 
            XPathFactory factory = XPathFactory.newInstance();
            XPath xpath = factory.newXPath();
            XPathExpression expr = xpath.compile(configValueXPath);
 
            Object result = expr.evaluate(doc);
 
            printDoc(doc.getChildNodes(), ""); // print nodes and attributes
 
        } catch (ParserConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SAXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (XPathExpressionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
Et voici ma chaine XPath:
/configuration/logger[@name='Lua']/level/@value='DEBUG'
Donc ensuite, si j'affiche mon Document, il n'a pas changé... pourquoi?

Et un extrait de mon xml:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <logger name="com" />
    <logger name="com.nexthink.portal">
        <level value="INFO" />
    </logger>
    <logger name="Lua">
        <level value="INFO" />
    </logger>
</configuration>
Merci d'avance!

A+