gnodet commented on code in PR #11823:
URL: https://github.com/apache/maven/pull/11823#discussion_r2986057176
##########
impl/maven-xml/src/main/java/org/apache/maven/internal/xml/DefaultXmlService.java:
##########
Review Comment:
_Claude Code on behalf of Guillaume Nodet_
Good question — the `elementName == null` check is how this method
distinguishes the first `START_ELEMENT` event (which is "this" element being
parsed) from subsequent `START_ELEMENT` events (which are children, handled in
the `else` branch). The method is called recursively for each child, and
`elementName` starts as `null` — once the first start tag is seen, it gets set,
so all further start tags within the same call are children. Added a comment to
clarify this.
##########
impl/maven-xml/src/main/java/org/apache/maven/internal/xml/DefaultXmlService.java:
##########
@@ -68,10 +69,14 @@ public XmlNode doRead(Reader reader, @Nullable
XmlService.InputLocationBuilder l
@Override
public XmlNode doRead(XMLStreamReader parser, @Nullable
XmlService.InputLocationBuilder locationBuilder)
throws XMLStreamException {
- return doBuild(parser, DEFAULT_TRIM, locationBuilder);
+ return doBuild(parser, DEFAULT_TRIM, locationBuilder, new HashMap<>());
}
- private XmlNode doBuild(XMLStreamReader parser, boolean trim,
InputLocationBuilder locationBuilder)
+ private XmlNode doBuild(
+ XMLStreamReader parser,
+ boolean trim,
+ InputLocationBuilder locationBuilder,
+ Map<String, String> parentNamespaces)
throws XMLStreamException {
boolean spacePreserve = false;
String lPrefix = null;
Review Comment:
_Claude Code on behalf of Guillaume Nodet_
Agreed — renamed `lPrefix` → `elementPrefix`, `lName` → `elementName`,
`lNamespaceUri` → `elementNamespaceUri`, `lValue` → `elementValue`. Also
renamed `aName`/`aValue`/`aPrefix` → `attrName`/`attrValue`/`attrPrefix` in the
attribute loop.
##########
impl/maven-xml/src/main/java/org/apache/maven/internal/xml/DefaultXmlService.java:
##########
@@ -93,6 +99,15 @@ private XmlNode doBuild(XMLStreamReader parser, boolean
trim, InputLocationBuild
lNamespaceUri = parser.getNamespaceURI();
lName = parser.getLocalName();
location = locationBuilder != null ?
locationBuilder.toInputLocation(parser) : null;
+ // Build the namespace context: start with inherited, add
local declarations
+ nsContext = new HashMap<>(parentNamespaces);
+ for (int i = 0; i < namespacesSize; i++) {
+ String nsPrefix = parser.getNamespacePrefix(i);
+ String nsUri = parser.getNamespaceURI(i);
+ if (nsPrefix != null && !nsPrefix.isEmpty()) {
Review Comment:
_Claude Code on behalf of Guillaume Nodet_
Correct — the default namespace (empty prefix) is intentionally excluded
from `namespaces()`. Per the XML namespace spec (Section 6.2), default
namespace declarations do NOT apply to attributes, so it would never be useful
for resolving prefixed attributes. Added a comment explaining this. We also
have `testParseDefaultNamespaceNotInNamespacesMap` that verifies this behavior.
--
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]