Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions scripts/match_dummy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import os
from lxml import etree
from collections import defaultdict

XSD_NAMESPACE = "http://www.w3.org/2001/XMLSchema"
NSMAP = {"xsd": XSD_NAMESPACE}

def find_elements_with_dummy_pair(root_dir):
dummy_elements = defaultdict(list) # map: base_name -> [(filepath, etree_element)]
normal_elements = defaultdict(list)

for dirpath, _, filenames in os.walk(root_dir):
for filename in filenames:
if not filename.endswith(".xsd"):
continue
filepath = os.path.join(dirpath, filename)
try:
tree = etree.parse(filepath)
except Exception as e:
print(f"Error parsing {filepath}: {e}")
continue

for elem in tree.xpath("//xsd:element", namespaces=NSMAP):
name = elem.get("name")
if not name:
continue
if name.endswith("_Dummy"):
base = name[:-6]
dummy_elements[base].append((filepath, elem))
else:
normal_elements[name].append((filepath, elem))

# Nu zoeken naar matchende paren
for base in sorted(dummy_elements):
if base in normal_elements:
for dummy_file, _ in dummy_elements[base]:
for normal_file, normal_elem in normal_elements[base]:
if normal_elem.get("abstract") == "true":
print(f"Pair: {base}_Dummy in {dummy_file}")
print(f" {base} in {normal_file}")
print()

if __name__ == "__main__":
# Vervang dit pad door jouw projectpad
find_elements_with_dummy_pair("./xsd")

74 changes: 74 additions & 0 deletions scripts/rename.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import glob
from lxml import etree

XSD_NS = "http://www.w3.org/2001/XMLSchema"
NSMAP = {"xs": XSD_NS}

# Attributen met één enkele type-ref
SINGLE_REF_ATTRS = {'type', 'base', 'ref', 'substitutionGroup', 'itemType'}

# Attributen met meerdere type-refs (spatiegescheiden)
MULTI_REF_ATTRS = {'memberTypes'}

def collect_renames(xsd_files):
rename_map = {}
for file in xsd_files:
tree = etree.parse(file)
for tag in ['xs:element', 'xs:complexType', 'xs:simpleType']:
for elem in tree.xpath(f'//{tag}', namespaces=NSMAP):
name = elem.get("name")
if name and name.endswith("_"):
rename_map[name] = name + "Dummy"
# if name and name.endswith("_DummyTypeAbstract"):
# rename_map[name] = name.replace('_DummyTypeAbstract', "_Abstract")
return rename_map

def apply_renames(xsd_files, rename_map):
for file in xsd_files:
tree = etree.parse(file)
root = tree.getroot()
changed = False

for elem in root.iter():
# Pas name aan
if "name" in elem.attrib:
old = elem.attrib["name"]
if old in rename_map:
elem.attrib["name"] = rename_map[old]
changed = True

# Pas enkelvoudige verwijzingen aan
for attr in SINGLE_REF_ATTRS:
if attr in elem.attrib:
value = elem.attrib[attr]
if ":" not in value and value in rename_map:
elem.attrib[attr] = rename_map[value]
changed = True

# Pas meervoudige verwijzingen aan (zoals bij xs:union)
for attr in MULTI_REF_ATTRS:
if attr in elem.attrib:
values = elem.attrib[attr].split()
new_values = [
rename_map.get(v, v) if ':' not in v else v
for v in values
]
if new_values != values:
elem.attrib[attr] = ' '.join(new_values)
changed = True

if changed:
print(f"Updated {file}")
tree.write(file, encoding="utf-8", xml_declaration=True, pretty_print=True)

def main():
xsd_files = glob.glob("xsd/**/*.xsd", recursive=True)
rename_map = collect_renames(xsd_files)
if not rename_map:
print("Geen hernoemingen nodig.")
return
print("Te hernoemen:", rename_map)
apply_renames(xsd_files, rename_map)

if __name__ == "__main__":
main()
32 changes: 16 additions & 16 deletions xsd/NX.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@
<xsd:element name="organisations" minOccurs="0">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Organisation_" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="OrganisationRef_"/>
<xsd:element ref="Organisation_Dummy" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="OrganisationRef_Dummy"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Expand All @@ -147,15 +147,15 @@
<xsd:element name="assignments" minOccurs="0">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Assignment_"/>
<xsd:element ref="Assignment_Dummy"/>
<xsd:element ref="AssignmentRef"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="priceableObjects" minOccurs="0">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="PriceableObject_" maxOccurs="unbounded"/>
<xsd:element ref="PriceableObject_Dummy" maxOccurs="unbounded"/>
<xsd:element ref="PriceableObjectRef"/>
</xsd:sequence>
</xsd:complexType>
Expand Down Expand Up @@ -280,7 +280,7 @@
<xsd:element name="quality" minOccurs="0">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="QualityStructureFactor_" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="QualityStructureFactor_Dummy" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Expand All @@ -307,7 +307,7 @@
<xsd:element name="usageParameters" minOccurs="0">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="UsageParameter_" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="UsageParameter_Dummy" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="UsageParameterPrice" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="TypeOfUsageParameter" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="TypeOfConcession" minOccurs="0"/>
Expand All @@ -325,7 +325,7 @@
<xsd:element name="fareProducts" minOccurs="0">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="FareProduct_" maxOccurs="unbounded"/>
<xsd:element ref="FareProduct_Dummy" maxOccurs="unbounded"/>
<xsd:element ref="ChargingMoment" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="TypeOfFareProduct" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="AccessRightInProduct" minOccurs="0" maxOccurs="unbounded"/>
Expand Down Expand Up @@ -381,22 +381,22 @@
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="PriceUnit" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="FarePrice_" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="FarePrice_Dummy" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="priceGroups" minOccurs="0">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="PriceGroup_"/>
<xsd:element ref="Cell_"/>
<xsd:element ref="PriceGroup_Dummy"/>
<xsd:element ref="Cell_Dummy"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="priceableObjects" minOccurs="0">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="PriceableObject_"/>
<xsd:element ref="PriceableObject_Dummy"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Expand Down Expand Up @@ -469,7 +469,7 @@
<xsd:element name="routes" minOccurs="0">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Route_" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="Route_Dummy" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="RouteLink" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="RoutePoint" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
Expand All @@ -486,7 +486,7 @@
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="GroupOfLines" maxOccurs="unbounded"/>
<xsd:element ref="Line_" maxOccurs="unbounded"/>
<xsd:element ref="Line_Dummy" maxOccurs="unbounded"/>
<xsd:element ref="Direction" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
Expand Down Expand Up @@ -538,7 +538,7 @@
<xsd:annotation>
<xsd:documentation>JOURNEY PATTERN.</xsd:documentation>
</xsd:annotation>
<xsd:element ref="JourneyPattern_" maxOccurs="unbounded"/>
<xsd:element ref="JourneyPattern_Dummy" maxOccurs="unbounded"/>
<xsd:element ref="TimingLinkInJourneyPattern" maxOccurs="unbounded"/>
<xsd:element ref="StopPointInJourneyPattern" maxOccurs="unbounded"/>
</xsd:sequence>
Expand All @@ -560,7 +560,7 @@
<xsd:element name="journeys" minOccurs="0">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element ref="Journey_"/>
<xsd:element ref="Journey_Dummy"/>
<xsd:element ref="JourneyPart" maxOccurs="unbounded"/>
<xsd:element ref="JourneyPartCouple"/>
<xsd:element ref="GroupOfServices" maxOccurs="1"/>
Expand All @@ -573,7 +573,7 @@
<xsd:choice maxOccurs="unbounded">
<xsd:element ref="InterchangeRule"/>
<xsd:element ref="JourneyMeeting" maxOccurs="unbounded"/>
<xsd:element ref="Interchange_"/>
<xsd:element ref="Interchange_Dummy"/>
</xsd:choice>
</xsd:complexType>
</xsd:element>
Expand Down
2 changes: 1 addition & 1 deletion xsd/ifopt.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<xsd:element name="organisations" minOccurs="0">
<xsd:complexType>
<xsd:sequence minOccurs="0" maxOccurs="1">
<xsd:element ref="Organisation_" maxOccurs="unbounded"/>
<xsd:element ref="Organisation_Dummy" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ Rail transport, Roads and Road transport
<xsd:documentation>NetEX: GENERAL ASSIGNMENT types for NeTEx Network Exchange.</xsd:documentation>
</xsd:annotation>
<!-- ======================================================================= -->
<xsd:element name="Assignment_" type="DataManagedObjectStructure" abstract="true" substitutionGroup="DataManagedObject">
<xsd:element name="Assignment_Dummy" type="DataManagedObjectStructure" abstract="true" substitutionGroup="DataManagedObject">
<xsd:annotation>
<xsd:documentation>Dummy Abstract Assignment. An Assignment assigns a property to an other element. It has a name and an order.</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:complexType name="Assignment_VersionStructure_" abstract="true">
<xsd:complexType name="Assignment_VersionStructure_Dummy" abstract="true">
<xsd:annotation>
<xsd:documentation>Type for ASSIGNMENT.</xsd:documentation>
</xsd:annotation>
Expand Down Expand Up @@ -97,7 +97,7 @@ Rail transport, Roads and Road transport
</xsd:element>
</xsd:sequence>
</xsd:group>
<xsd:element name="Assignment" abstract="true" substitutionGroup="Assignment_">
<xsd:element name="Assignment" abstract="true" substitutionGroup="Assignment_Dummy">
<xsd:annotation>
<xsd:documentation>A set of properties to be applied to an another element. It has a name and an order.</xsd:documentation>
</xsd:annotation>
Expand Down Expand Up @@ -125,7 +125,7 @@ Rail transport, Roads and Road transport
<xsd:documentation>Type for ASSIGNMENT.</xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:restriction base="Assignment_VersionStructure_">
<xsd:restriction base="Assignment_VersionStructure_Dummy">
<xsd:sequence>
<xsd:sequence>
<xsd:group ref="EntityInVersionGroup" minOccurs="0"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Rail transport, Roads and Road transport
</xsd:annotation>
<xsd:restriction base="ObjectIdType"/>
</xsd:simpleType>
<xsd:element name="GroupOfEntitiesRef_" type="VersionOfObjectRefStructure" abstract="true" substitutionGroup="VersionOfObjectRef">
<xsd:element name="GroupOfEntitiesRef_Dummy" type="VersionOfObjectRefStructure" abstract="true" substitutionGroup="VersionOfObjectRef">
<xsd:annotation>
<xsd:documentation>Reference to a GROUP OF ENTITies.</xsd:documentation>
</xsd:annotation>
Expand All @@ -84,7 +84,7 @@ Rail transport, Roads and Road transport
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="GroupOfEntitiesRefStructure_" abstract="true">
<xsd:complexType name="GroupOfEntitiesRefStructure_Dummy" abstract="true">
<xsd:annotation>
<xsd:documentation>Extending Type for a reference to a GROUP OF ENTITies.</xsd:documentation>
</xsd:annotation>
Expand All @@ -103,7 +103,7 @@ Rail transport, Roads and Road transport
<xsd:documentation>Extending Type for a reference to a GROUP OF ENTITies.</xsd:documentation>
</xsd:annotation>
<xsd:simpleContent>
<xsd:restriction base="GroupOfEntitiesRefStructure_">
<xsd:restriction base="GroupOfEntitiesRefStructure_Dummy">
<xsd:attribute name="ref" type="GroupOfEntitiesIdType" use="required">
<xsd:annotation>
<xsd:documentation>Identifier of referenced entity.</xsd:documentation>
Expand Down Expand Up @@ -159,7 +159,7 @@ Rail transport, Roads and Road transport
</xsd:annotation>
<xsd:restriction base="GroupOfEntitiesIdType"/>
</xsd:simpleType>
<xsd:element name="GeneralGroupOfEntitiesRef" type="GeneralGroupOfEntitiesRefStructure" abstract="false" substitutionGroup="GroupOfEntitiesRef_">
<xsd:element name="GeneralGroupOfEntitiesRef" type="GeneralGroupOfEntitiesRefStructure" abstract="false" substitutionGroup="GroupOfEntitiesRef_Dummy">
<xsd:annotation>
<xsd:documentation>Reference to a GENERAL GROUP OF ENTITies.</xsd:documentation>
</xsd:annotation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Rail transport, Roads and Road transport
</xsd:annotation>
<xsd:restriction base="GroupOfEntitiesIdType"/>
</xsd:simpleType>
<xsd:element name="LayerRef" type="LayerRefStructure" substitutionGroup="GroupOfEntitiesRef_">
<xsd:element name="LayerRef" type="LayerRefStructure" substitutionGroup="GroupOfEntitiesRef_Dummy">
<xsd:annotation>
<xsd:documentation>Reference to a LAYER.</xsd:documentation>
</xsd:annotation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Rail transport, Roads and Road transport
</xsd:annotation>
<xsd:restriction base="GroupOfEntitiesIdType"/>
</xsd:simpleType>
<xsd:element name="LogRef" type="LogRefStructure" abstract="false" substitutionGroup="GroupOfEntitiesRef_">
<xsd:element name="LogRef" type="LogRefStructure" abstract="false" substitutionGroup="GroupOfEntitiesRef_Dummy">
<xsd:annotation>
<xsd:documentation>Reference to a LOG.</xsd:documentation>
</xsd:annotation>
Expand Down
Loading