XMLStreamWriter.writeStartElement(prefix,localName,namespaceURI), Prefix "manifest" can not be resolved to namespace URI
source.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<zip:archive xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" xmlns:zip="com.test.zip">
<zip:entry zip:target="test1.xml"><manifest:manifest>aaa</manifest:manifest></zip:entry>
<zip:entry zip:target="test2.xml">.......</zip:entry>
</zip:archive>
I use javax.xml.stream.XMLStreamReader
to read source.xml
file, do some action, and then write to disk according to the attribute value of zip:target
.
the result file, test1.xm开发者_JAVA百科l:
<?xml version="1.0" encoding="UTF-8"?>
<manifest:manifest>aaa</manifest:manifest>
You know, it is wrong. Prefix "manifest" can not be resolved to namespace URI.
Through the debugging, I found the following statement was successfully called.
XMLStreamWriter.writeStartElement("manifest", "manifest", "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0");
The third parameter of writeStartElement is not null. But why is the namespace missing in the result file?
I tried two methods:
- set sRepairingNamespaces to be true
- add writeNamespace after writeStartElement
But new trouble come, the namespaces were redeclared and duplicate.
I believe you need to setPrefix before writeStartElement. I don't think you'll need sRepairingNamespaces - but I'm not sure.
精彩评论