Skip to content

Commit 6b741c3

Browse files
committed
Improved default attribute value extraction
1 parent 09b9934 commit 6b741c3

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

ts/RelaxNGParser.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,26 @@ export class RelaxNGParser {
229229
}
230230

231231
private findDefaultValueFromChildren(attribute: XMLElement): string | undefined {
232+
// Search depth-first for any compatibility "defaultValue" element among descendants
233+
const stack: XMLElement[] = [];
232234
for (const child of attribute.getChildren()) {
233-
if (this.getLocalNameFromElement(child) === "defaultValue") {
234-
return child.getText().trim();
235+
if (child.getNodeType() === Constants.ELEMENT_NODE) {
236+
stack.push(child as XMLElement);
235237
}
236238
}
239+
240+
while (stack.length > 0) {
241+
const node: XMLElement = stack.pop() as XMLElement;
242+
if (this.getLocalNameFromElement(node) === "defaultValue") {
243+
return node.getText().trim();
244+
}
245+
for (const child of node.getChildren()) {
246+
if (child.getNodeType() === Constants.ELEMENT_NODE) {
247+
stack.push(child as XMLElement);
248+
}
249+
}
250+
}
251+
237252
return undefined;
238253
}
239254

0 commit comments

Comments
 (0)