diff --git a/src/avtas/lmcp/lmcpgen/MDM.DTD b/src/avtas/lmcp/lmcpgen/MDM.DTD index e04b40e..1594c04 100644 --- a/src/avtas/lmcp/lmcpgen/MDM.DTD +++ b/src/avtas/lmcp/lmcpgen/MDM.DTD @@ -43,6 +43,7 @@ Extends CDATA '' Name CDATA #REQUIRED Series CDATA '' + ID CDATA '' > diff --git a/src/avtas/lmcp/lmcpgen/MDMReader.java b/src/avtas/lmcp/lmcpgen/MDMReader.java index b2cb152..b7cd682 100644 --- a/src/avtas/lmcp/lmcpgen/MDMReader.java +++ b/src/avtas/lmcp/lmcpgen/MDMReader.java @@ -108,9 +108,21 @@ public static MDMInfo getFromXML(Node node) throws Exception { } info.structs = fillStructs(XMLUtil.getList(node, "StructList", "Struct"), info); + + // Determine start ID by looking for the maximum specified ID (0 by default) + for (int i = 0; i < info.structs.length; i++) { + startId = Math.max(startId, info.structs[i].id + 1); + } + + // Assign IDs for structs that do not yet have one + int idOffset = 0; for (int i = 0; i < info.structs.length; i++) { - info.structs[i].id = startId + i; + if (info.structs[i].id < 1) { + info.structs[i].id = startId + idOffset; + idOffset++; + } } + info.enums = fillEnums(XMLUtil.getList(node, "EnumList", "Enum"), info); return info; @@ -154,6 +166,12 @@ public static StructInfo[] fillStructs(Node[] list, MDMInfo mdm) throws Exceptio struct.comment = getComment(list[i]).replaceAll("[\n\r\f]+", ""); } + // Optional explicit ID + String idStr = XMLUtil.getAttribute(list[i], "ID", ""); + if (!idStr.isEmpty()) { + struct.id = Integer.parseInt(idStr); + } + Node[] fieldNodes; fieldNodes = XMLUtil.getChildren(list[i], "Field");