gnodet commented on code in PR #11823:
URL: https://github.com/apache/maven/pull/11823#discussion_r2982267531
##########
impl/maven-xml/src/main/java/org/apache/maven/internal/xml/DefaultXmlService.java:
##########
@@ -178,6 +176,42 @@ private void writeNode(XMLStreamWriter xmlWriter, XmlNode
node) throws XMLStream
xmlWriter.writeEndElement();
}
+ static void writeAttributes(XMLStreamWriter xmlWriter, Map<String, String>
attributes) throws XMLStreamException {
+ // Write namespace declarations first, then regular attributes
+ for (Map.Entry<String, String> attr : attributes.entrySet()) {
+ String key = attr.getKey();
+ if ("xmlns".equals(key)) {
+ xmlWriter.writeDefaultNamespace(attr.getValue());
+ } else if (key.startsWith("xmlns:")) {
+ xmlWriter.writeNamespace(key.substring(6), attr.getValue());
+ }
+ }
+ for (Map.Entry<String, String> attr : attributes.entrySet()) {
Review Comment:
_Claude Code on behalf of Guillaume Nodet_
Fixed — renamed to `attribute`.
##########
impl/maven-xml/src/main/java/org/apache/maven/internal/xml/DefaultXmlService.java:
##########
@@ -178,6 +176,42 @@ private void writeNode(XMLStreamWriter xmlWriter, XmlNode
node) throws XMLStream
xmlWriter.writeEndElement();
}
+ static void writeAttributes(XMLStreamWriter xmlWriter, Map<String, String>
attributes) throws XMLStreamException {
+ // Write namespace declarations first, then regular attributes
+ for (Map.Entry<String, String> attr : attributes.entrySet()) {
+ String key = attr.getKey();
+ if ("xmlns".equals(key)) {
+ xmlWriter.writeDefaultNamespace(attr.getValue());
+ } else if (key.startsWith("xmlns:")) {
+ xmlWriter.writeNamespace(key.substring(6), attr.getValue());
+ }
+ }
+ for (Map.Entry<String, String> attr : attributes.entrySet()) {
+ String key = attr.getKey();
+ String value = attr.getValue();
+ if ("xmlns".equals(key) || key.startsWith("xmlns:")) {
+ continue; // already written above
+ } else if (key.startsWith("xml:")) {
Review Comment:
_Claude Code on behalf of Guillaume Nodet_
You're right that the `xml:` prefix is predefined and must not be declared.
However, we can't make this branch empty — attributes like
`xml:space="preserve"` still need to be written to the output. If we skip them,
whitespace preservation would be lost on round-trip. The
`writeAttribute(namespaceURI, localName, value)` call is the correct StAX way
to write them — it writes the attribute with the proper namespace without
declaring the prefix (since it's predefined). Added a comment to explain this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]