2011-07-28 76 views
0

感謝以前的答覆,如何使用SAX解析器

我是新來解析用java概念來刪除一個元素,任何人都可以指導我如何修改使用的SAXParser的XML。我搜索了很長時間來刪除標籤,但我不知道如何刪除。請指引我

+3

請解釋一下你的意思。您不能使用SAX解析器刪除元素,因爲SAX解析器會爲每個元素生成事件。您可以處理特定事件,或只是忽略它,但不能刪除。 –

回答

1

您可以刪除使用這個元素:

SAXReader reader = new SAXReader(); 
reader.setEncoding(CharEncoding.UTF_8); 
Document customXmlDocument = reader.read(inputStream); 
// Get the element you want to remove and then pass it to the remove method as so 
customXmlDocument.remove(Element)