How can I change the namespace on every node in a DOM?

前端 未结 8 689
小蘑菇
小蘑菇 2020-12-19 10:05

How can I, given a w3c DOM (Java\'s default implementation, specifically) change the namespace of every element/attribute/node in that DOM? Efficiently, preferably. The DO

8条回答
  •  死守一世寂寞
    2020-12-19 10:35

    You may copy your DOM tree to another tree and make some tweaks during process. For example, using org.apache.xml.utils.DOMBuilder as the implementation of ContentHandler, you may override methods in such way:

    public void startElement(String ns, String localName, String name, Attributes atts) throws SAXException {
            super.startElement("new_namespace", localName, name, atts);
        }
    

    DOMBuilder will handle all dirty work during copying leaving to you only namespace replacement logic.

提交回复
热议问题