Processing as XML file.

I have a directory structure and a GDML file as follows <!DOCTYPE xml [ <!ENTITY define SYSTEM "DC1_define.xml"> <!ENTITY materials SYSTEM "DC1_materials.xml"> <!ENTITY solids SYSTEM "DC1_solids.xml"> <!ENTITY setup SYSTEM "DC1_setup.xml"> <!ENTITY struct SYSTEM "DC1_struct.xml"> ]> <xml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://service-spi.web.cern.ch/service-spi/app/releases/GDML/schema/gdml.xsd">&define;&materials;&solids;&setup;&struct;</xml> Where the files labelled with .xml type are not strictlly xml files as they have no <xml> ...content ... </xml> just valid include contents It is processed by try: from lxml import etree parser = etree.XMLParser(resolve_entities=True) root = etree.parse(filename, parser=parser) # print('error log') # print(parser.error_log) except ImportError: try: import xml.etree.ElementTree as etree FreeCAD.Console.PrintMessage( "running with etree.ElementTree (import limitations)\n" ) FreeCAD.Console.PrintMessage( " for full import add lxml library \n" ) tree = etree.parse(filename) This all works fine BUT I now wish to implement other functions which process the files listed in the Entities as individual xml files, Is there a way to achieve this? or alternatively is there a way to use an actual xml file as a include. -- ========== Art & Ceramics =========== https://www.instagram.com/ksloan1952/

Keith Sloan wrote at 2023-10-27 18:27 +0100:
You can "wrap" those files into a "prolog ... epilog". If the files are small, you can use: parsed = lxml.etree.fromstring(PROLOG + open(file).read() + EPILOG) If the files are so large that you do not want their content in memory, you can use a wrapper class, which first produces the PROLOG, then the file content and finally the EPILOG.

Keith Sloan wrote at 2023-10-27 18:27 +0100:
You can "wrap" those files into a "prolog ... epilog". If the files are small, you can use: parsed = lxml.etree.fromstring(PROLOG + open(file).read() + EPILOG) If the files are so large that you do not want their content in memory, you can use a wrapper class, which first produces the PROLOG, then the file content and finally the EPILOG.
participants (2)
-
Dieter Maurer
-
Keith Sloan