Import XML

TimvH
2011-05-20
2024-06-28
  • TimvH

    TimvH - 2011-05-20

    I wanted to create a script which could import an XML file.
    I first exported a GVL and wanted to import it, but I noticed it was placed in the POU pool.
    With this example it places it "under" the application of the Device.

    Create the .xml file, open a project with a device (PLC) and application and run the script.

    \# script example importXML.py
    \# current project
    proj = projects.primary
    \# create the import reporter
    class Reporter(ImportReporter):
        def error(self, message):
            system.write_message(Severity.Error, message)
        def warning(self, message):
            system.write_message(Severity.Warning, message)
        def resolve_conflict(self, obj):
            return ConflictResolve.Copy
        def added(self, obj):
            print("added: ", obj)
        def replaced(self, obj):
            print("replaced: ", obj)
        def skipped(self, obj):
            print("skipped: ", obj)
        
        @property
        def aborting(self):
            return False
    \# create the importer instance.
    reporter = Reporter()   
      
    \# import xml
    obj = proj.find("Application", True)
    i = len(obj)
    print("number of item Application: {0}".format(i))
    if i > 0:
       obj[0].import_xml(reporter,r"C:\_d\Python\importXML\myXML.xml")
       print("add item")
    
     
    👍
    1
  • aoj - 2011-10-19

    Hi TimvH,

    I wrote a script, which imports a XML to CoDeSys. Than I saw here in the forum, that you had created a script for importing XML. You defined in your script a class "Reporter". Could you please explain the function of this class. Is it important to have this class in the script?

    Thanks a lot.

     
  • TimvH

    TimvH - 2011-10-19

    You can see that the import function uses the reporter class, therefore I added it.
    The example is based on an example in the help and some addional help from 3S-Software.

     
    👍
    1
  • Anonymous - 2011-10-19

    Originally created by: M.Schaber

    Hi,

    The import and export process gives notifications about errors, warnings and progress. The purpose of the reporter is to process those notifications during the export or import process.

    For native export, passing the reporters is optional. For PLCOpenXML, we're working on making them optional.

    HTH,
    Markus

     
  • Lohr-DCIA-EHE1 - 2012-03-20

    I had exported some properties of a function block as XML-file using the menu function "Export PLCopen XML" and then wanted to import that with the function import_xml(). That worked fine, but all commentaries of the properties were not imported.

    Example:

    // P-0-0011 -READ- Last valid position command value <-- This was not imported !!!
    PROPERTY P_0_0011 : DINT <-- This was imported !!!

     
  • Anonymous - 2012-03-20

    Originally created by: M.Schaber

    Hi, Lohr_DCIA-EHE1,

    Lohr_DCIA-EHE1 hat geschrieben:
    I had exported some properties of a function block as XML-file using the menu function "Export PLCopen XML" and then wanted to import that with the function import_xml(). That worked fine, but all commentaries of the properties were not imported.
    Example:
    // P-0-0011 -READ- Last valid position command value <-- This was not imported !!!
    PROPERTY P_0_0011 : DINT <-- This was imported !!!

    Can check whether the comments are correctly imported when you do the import via the menu function?

     
  • Lohr-DCIA-EHE1 - 2012-03-20

    The import of the commentaries of the properties via the menu function does not work either.

    All commentaries above FUNCTION_BLOCK MX_DirectVarAxis are lost, too !!

    // {attribute 'signature_flag' := '12345'} <-- lost
    //{attribute 'hide'}//hide POU <-- lost
    {attribute 'signature_flag' := '1275068416'} <-- lost
    FUNCTION_BLOCK MX_DirectVarAxis <-- from here on everything is copied.
    VAR
    //{attribute 'hide'}//hide POU
    {attribute 'noinit'}
    usCmdAchse : UINT; // Achse fuer den Parameter-Zugriff
    END_VAR

     
  • Anonymous - 2012-03-20

    Originally created by: M.Schaber

    Lohr_DCIA-EHE1 hat geschrieben:
    The import of the commentaries of the properties via the menu function does not work either.
    All commentaries above FUNCTION_BLOCK MX_DirectVarAxis are lost, too !!
    // {attribute 'signature_flag' := '12345'} <-- lost
    //{attribute 'hide'}//hide POU <-- lost
    {attribute 'signature_flag' := '1275068416'} <-- lost
    FUNCTION_BLOCK MX_DirectVarAxis <-- from here on everything is copied.
    VAR
    //{attribute 'hide'}//hide POU
    {attribute 'noinit'}
    usCmdAchse : UINT; // Achse fuer den Parameter-Zugriff
    END_VAR

    Then it's a general PLCOpenXML problem, and not specific to scripting. So I'm afraid I'm not in charge of it.

    I think the best is that you file a bug report via our support department. Especially mention that the {attribute}s are lost, as that information is more important than "noarmal" comments.

     
  • codesysdave

    codesysdave - 2024-06-28

    Great info from 2011... thanks!

     

Log in to post a comment.