Skip to content

Commit ff5158e

Browse files
committed
[Java] Fix lookup of types ancestor for PR #904.
1 parent a52aef5 commit ff5158e

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/XmlSchemaParser.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,15 +327,26 @@ public static String getAttributeValue(final Node elementNode, final String attr
327327
}
328328

329329
/**
330-
* To be used with child elements of {@code <types>} elements. Returns the package attribute as
331-
* defined on the parent {@code <types>} element
330+
* To be used with descendant elements of {@code <types>} elements. Returns the package attribute value as
331+
* defined on the ancestor {@code <types>} element.
332332
*
333-
* @param elementNode the node inside the types element
334-
* @return the package name, or null if not defined
333+
* @param elementNode the node inside the {@code <types>} element.
334+
* @return the package name, or null if not defined.
335335
*/
336336
public static String getTypesPackageAttribute(final Node elementNode)
337337
{
338-
return getAttributeValue(elementNode.getParentNode(), "package", null);
338+
Node parentNode = elementNode.getParentNode();
339+
while (null != parentNode)
340+
{
341+
if ("types".equals(parentNode.getLocalName()) || "types".equals(parentNode.getNodeName()))
342+
{
343+
return getAttributeValue(parentNode, "package", null);
344+
}
345+
346+
parentNode = parentNode.getParentNode();
347+
}
348+
349+
return null;
339350
}
340351

341352
/**

0 commit comments

Comments
 (0)