Details
-
Type:
Bug
-
Status:
In Progress
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 4.0.5
-
Fix Version/s: None
-
Labels:None
-
Number of attachments :
Description
Code like the following gets a validation error at the first writeStartElement, even though the XML that comes out is correct.
The following create the same XML. In both cases, the root element ends up in the 'default' namespace.
Fails:
XMLStreamWriter writer = getXmlWriter(fos);
writer.writeStartDocument("utf-8", "1.0");
writer.writeStartElement("model");
writer.writeDefaultNamespace(METADATA_NAMESPACE);
// change for new word class mechanism
writer.writeAttribute("version", "2");
writer.writeStartElement( "build");
Succeeds:
XMLStreamWriter writer = getXmlWriter(fos);
writer.writeStartDocument("utf-8", "1.0");
writer.writeStartElement("", "model", METADATA_NAMESPACE);
writer.writeDefaultNamespace(METADATA_NAMESPACE);
// change for new word class mechanism
writer.writeAttribute("version", "2");
writer.writeStartElement("", "build", METADATA_NAMESPACE);
Hmmh. This is problematic... mostly because the way things work, namespace for the element basically changes due to declaration (unless I forgot details of how writer-side validation works).
This because validation call for element itself is done before element and namespace output.
This is assumed based on sample code:
If so, code would be incorrect; as code implies that the element is not to be in any namespace.
If it should be in the namespace, it should call one of alternative writeStartElement methods, where expected namespace (URI) is passed explicitly. In non-repairing mode, the full (3-arg) variant is probably what is needed.
So, it may be a bug in sample code, but only if my understanding of the code is correct.