简体   繁体   中英

Saxon 9 doesn't understand renameNode() from Xerces

I have a DOM Document created by DocumentBuilder of Apache Xerces 2.1.9:

<x xmlns="#old-namespace">hello, world</x>

Now I'm renaming its root node in order to change the namespace:

Element root = dom.getDocumentElement();
dom.renameNode(root, "x", "#new-namespace");

Then, I'm transforming the document into text/xml, using Saxon 9, and root node is not changing its namespace.

Is it a known bug/incompatibility? With Saxon 8.7 exactly the same code works without problems. If necessary, I can post the entire code.

Unfortunately DOM APIs allow you to create a DOM that is internally inconsistent. There is more than one way of determining the namespace URI of an element, and if the DOM is inconsistent these may give difference answers (for example, the namespace URI property of the node might not correspond to the namespace URI obtained by resolving the prefix against the in-scope namespaces. There's not much Saxon can do about this.

(Best answer is not to use DOM, but some more "modern" tree model, such as XOM or JDOM2).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM