guhai
guhai

Reputation: 187

XMLStreamWriter.writeStartElement(prefix,localName,namespaceURI): no binding of prefix to namespace

XMLStreamWriter.writeStartElement(prefix,localName,namespaceURI) (doc link)

The namespaceURI parameter is not null, but it failed to bind the prefix to the namespaceURI:

writeStartElement("manifest","manifest","urn:oasis:names:tc:opendocument:xmlns:manifest:1.0")

The result file:

<manifest:manifest>

But it should be:

<manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0">

Upvotes: 1

Views: 3472

Answers (2)

Ed Staub
Ed Staub

Reputation: 15690

I believe you need to setPrefix before writeStartElement. I don't think you'll need sRepairingNamespaces - but I'm not sure.

Upvotes: 0

prunge
prunge

Reputation: 23258

Set javax.xml.stream.isRepairingNamespaces property to true on the XMLOutputFactory used to construct your stream writer. By default it is turned off.

Accoding to the javadocs for writeStartElement() in XMLStreamWriter:

Throws: XMLStreamException - if the namespace URI has not been bound to a prefix and javax.xml.stream.isRepairingNamespaces has not been set to true

(for some reason the official javadocs don't show the detail text for the exception but my local downloaded ones do)

Either that or you need to explicitly call setPrefix() to register the namespaces first.

Upvotes: 1

Related Questions