2014-01-09 236 views
0

我試圖從我的XML與jdom2刪除節點,但我沒有找到答案刪除整個XML節點

我的XML是這樣的:

<?xml version="1.0" encoding="UTF-8"?> 
<banque> 
    <compte idCompte="5646"> 
    <numCompte>5646</numCompte> 
    <nom>Ludo</nom> 
    <solde>850</solde> 
    </compte> 
    <compte idCompte="4546"> 
    <numCompte>4546</numCompte> 
    <nom>Antoine</nom> 
    <solde>9999.4</solde> 
    </compte> 

我想我需要爲目標的屬性idCompte並刪除它,但我不知道如何做到這一點。

如果你有一個(簡單的)解決方案,我很高興地看到:)

+0

你想jdom2代碼刪除節點孔特的idComplete屬性? – Kick

+0

不一定 – Sneeky

回答

0
What you are trying to achieve is complex(multi-step process) in nature, 
I can share with you the steps(algorithm) that you need to follow: 

Step:1 
You need to genearte the schema first: 
Generate the schema from this online tool: 
http://www.xmlforasp.net/CodeBank/System_Xml_Schema/BuildSchema/BuildXMLSchema.aspx 

Step:2 
Using these schema generate the Java classes: 
using api tools like XMLBeans or JAXB 
a) scomp -out employeeschema.jar employeeschema.xsd (Ref: http://xmlbeans.apache.org/) 
b) xjc -d out customer.xsd (Ref: http://blog.bdoughan.com/2011/10/jaxb-xjc-imported-schemas-and-xml.html) 

Step:3 
Then follow below tutorial for your reference for in-depth CRUD operation that you want to perform on your XML: 
Jaxb: http://www.mkyong.com/java/jaxb-hello-world-example/ 
Xstream: http://x-stream.github.io/tutorial.html 
XMLBeans: http://xmlbeans.apache.org/documentation/tutorial_getstarted.html 
+0

謝謝你的步驟:)不過我已經找到了使用Xpath的stackoverflow中的解決方案我喜歡這篇文章或我的Java,如果我不回顧它。 – Sneeky