diff --git a/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/NetworkXml.java b/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/NetworkXml.java index 0e4f736c17c..4df274ba42e 100644 --- a/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/NetworkXml.java +++ b/iidm/iidm-xml-converter/src/main/java/com/powsybl/iidm/xml/NetworkXml.java @@ -221,19 +221,7 @@ private static void writeVoltageAngleLimits(Network n, NetworkXmlWriterContext c } private static void writeExtensions(Network n, NetworkXmlWriterContext context) throws XMLStreamException { - Collection> identifiables = n.getIdentifiables(); - if (supportSubnetworksExport(context)) { - identifiables = new LinkedHashSet<>(identifiables); - if (n.getParentNetwork() == n) { - // the subnetworks hold their extensions - identifiables.removeAll(n.getSubnetworks()); - } else { - // Subnetworks are not in their own identifiables. - identifiables.add(n); - } - } - - for (Identifiable identifiable : IidmXmlUtil.sorted(identifiables, context.getOptions())) { + for (Identifiable identifiable : IidmXmlUtil.sorted(n.getIdentifiables(), context.getOptions())) { if (!context.isExportedEquipment(identifiable) || !retainElement(identifiable, n, context)) { continue; } @@ -391,7 +379,7 @@ public static Anonymizer write(Network n, ExportOptions options, OutputStream os private static boolean retainElement(Identifiable element, Network n, NetworkXmlWriterContext context) { return !supportSubnetworksExport(context) || n.getId().equals(element.getId()) // the element is the network - || element.getParentNetwork() == n; // the element is directly in the network (not in one of its subnetworks) + || element.getParentNetwork() == n && element.getType() != IdentifiableType.NETWORK; // the element is directly in the network (not in one of its subnetworks) } private static boolean supportSubnetworksExport(NetworkXmlWriterContext context) {