Edit XML from geodatabase using Python element treeError importing XML workspace document to file...

Is "remove commented out code" correct English?

How to prevent "they're falling in love" trope

Why do bosons tend to occupy the same state?

Would Slavery Reparations be considered Bills of Attainder and hence Illegal?

How writing a dominant 7 sus4 chord in RNA ( Vsus7 chord in the 1st inversion)

What reasons are there for a Capitalist to oppose a 100% inheritance tax?

Can I run a new neutral wire to repair a broken circuit?

Is it inappropriate for a student to attend their mentor's dissertation defense?

CAST throwing error when run in stored procedure but not when run as raw query

Am I breaking OOP practice with this architecture?

How can I determine if the org that I'm currently connected to is a scratch org?

How much of data wrangling is a data scientist's job?

How do I handle a potential work/personal life conflict as the manager of one of my friends?

Why can't we play rap on piano?

Could the museum Saturn V's be refitted for one more flight?

Apex Framework / library for consuming REST services

Solving a recurrence relation (poker chips)

Is there a hemisphere-neutral way of specifying a season?

Is it possible to create a QR code using text?

Venezuelan girlfriend wants to travel the USA to be with me. What is the process?

How do conventional missiles fly?

Avoiding the "not like other girls" trope?

Assassin's bullet with mercury

Is there an expression that means doing something right before you will need it rather than doing it in case you might need it?



Edit XML from geodatabase using Python element tree


Error importing XML workspace document to file geodatabaseArcGIS XML Import Failed - how to find out why it failed?Changing attribute and/or text values in Esri metadata using PythonHow to use the output file of a script as an input file for the rest of the script in arcpy?Converting multiple File geodatabase (.gdb) into multiple Personal geodatabase (.mdb)Editing ArcGIS metadata elements using Python?Reading an ESRI XML Workspace Document with python or other FOSSArcCatalog import geodatabase xml schema: domain name conflictElement Tree and Regex













1















I am trying to disallow Null values for specific fields within a gdb. Changing field properties using arcpy.AlterField_managment only changes the properties in the Python object and not in the gdb schema. My workaround is to export an XML workspace document, make the changes using the element tree module in Python, then import the XML back into the gdb. When I go to import the XML back into the gdb ArcGIS gives me this error "Invalid XML file". I removed my code from the equation by just reading the XML workspace document into Python then directly writing it back out. I get the same error, so the issue is not with my code I am using to edit the input XML. Also I tried ET.parse() on the output_xml_file and it parses just fine. So the issue must be that element tree is changing my Esri workspace document when it parses it so that when I try to import back into gdb it doesn't recognize it.



import xml.etree.ElementTree as ET
ET.register_namespace('esri', "http://www.esri.com/schemas/ArcGIS/10.6")
ET.register_namespace('xsi', "http://www.w3.org/2001/XMLSchema-instance")
ET.register_namespace('xs', "http://www.w3.org/2001/XMLSchema")
tree = ET.parse(esri_workspace_doc_xml_file)
tree.write(output_xml_file)









share|improve this question
















bumped to the homepage by Community 5 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • Which field are you making NOT NULL? If geometry columns are in the list, then that would cause failure. Your question would be aided by a "context diff" of the pretty-printed before and after documents (the lines around the area where changes occurred, as displayed by diff -c)

    – Vince
    Jul 19 '18 at 3:21
















1















I am trying to disallow Null values for specific fields within a gdb. Changing field properties using arcpy.AlterField_managment only changes the properties in the Python object and not in the gdb schema. My workaround is to export an XML workspace document, make the changes using the element tree module in Python, then import the XML back into the gdb. When I go to import the XML back into the gdb ArcGIS gives me this error "Invalid XML file". I removed my code from the equation by just reading the XML workspace document into Python then directly writing it back out. I get the same error, so the issue is not with my code I am using to edit the input XML. Also I tried ET.parse() on the output_xml_file and it parses just fine. So the issue must be that element tree is changing my Esri workspace document when it parses it so that when I try to import back into gdb it doesn't recognize it.



import xml.etree.ElementTree as ET
ET.register_namespace('esri', "http://www.esri.com/schemas/ArcGIS/10.6")
ET.register_namespace('xsi', "http://www.w3.org/2001/XMLSchema-instance")
ET.register_namespace('xs', "http://www.w3.org/2001/XMLSchema")
tree = ET.parse(esri_workspace_doc_xml_file)
tree.write(output_xml_file)









share|improve this question
















bumped to the homepage by Community 5 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • Which field are you making NOT NULL? If geometry columns are in the list, then that would cause failure. Your question would be aided by a "context diff" of the pretty-printed before and after documents (the lines around the area where changes occurred, as displayed by diff -c)

    – Vince
    Jul 19 '18 at 3:21














1












1








1








I am trying to disallow Null values for specific fields within a gdb. Changing field properties using arcpy.AlterField_managment only changes the properties in the Python object and not in the gdb schema. My workaround is to export an XML workspace document, make the changes using the element tree module in Python, then import the XML back into the gdb. When I go to import the XML back into the gdb ArcGIS gives me this error "Invalid XML file". I removed my code from the equation by just reading the XML workspace document into Python then directly writing it back out. I get the same error, so the issue is not with my code I am using to edit the input XML. Also I tried ET.parse() on the output_xml_file and it parses just fine. So the issue must be that element tree is changing my Esri workspace document when it parses it so that when I try to import back into gdb it doesn't recognize it.



import xml.etree.ElementTree as ET
ET.register_namespace('esri', "http://www.esri.com/schemas/ArcGIS/10.6")
ET.register_namespace('xsi', "http://www.w3.org/2001/XMLSchema-instance")
ET.register_namespace('xs', "http://www.w3.org/2001/XMLSchema")
tree = ET.parse(esri_workspace_doc_xml_file)
tree.write(output_xml_file)









share|improve this question
















I am trying to disallow Null values for specific fields within a gdb. Changing field properties using arcpy.AlterField_managment only changes the properties in the Python object and not in the gdb schema. My workaround is to export an XML workspace document, make the changes using the element tree module in Python, then import the XML back into the gdb. When I go to import the XML back into the gdb ArcGIS gives me this error "Invalid XML file". I removed my code from the equation by just reading the XML workspace document into Python then directly writing it back out. I get the same error, so the issue is not with my code I am using to edit the input XML. Also I tried ET.parse() on the output_xml_file and it parses just fine. So the issue must be that element tree is changing my Esri workspace document when it parses it so that when I try to import back into gdb it doesn't recognize it.



import xml.etree.ElementTree as ET
ET.register_namespace('esri', "http://www.esri.com/schemas/ArcGIS/10.6")
ET.register_namespace('xsi', "http://www.w3.org/2001/XMLSchema-instance")
ET.register_namespace('xs', "http://www.w3.org/2001/XMLSchema")
tree = ET.parse(esri_workspace_doc_xml_file)
tree.write(output_xml_file)






python geodatabase-xml






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 19 '18 at 3:17









Vince

14.8k32849




14.8k32849










asked Jul 18 '18 at 23:20









cmittcmitt

62




62





bumped to the homepage by Community 5 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 5 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Which field are you making NOT NULL? If geometry columns are in the list, then that would cause failure. Your question would be aided by a "context diff" of the pretty-printed before and after documents (the lines around the area where changes occurred, as displayed by diff -c)

    – Vince
    Jul 19 '18 at 3:21



















  • Which field are you making NOT NULL? If geometry columns are in the list, then that would cause failure. Your question would be aided by a "context diff" of the pretty-printed before and after documents (the lines around the area where changes occurred, as displayed by diff -c)

    – Vince
    Jul 19 '18 at 3:21

















Which field are you making NOT NULL? If geometry columns are in the list, then that would cause failure. Your question would be aided by a "context diff" of the pretty-printed before and after documents (the lines around the area where changes occurred, as displayed by diff -c)

– Vince
Jul 19 '18 at 3:21





Which field are you making NOT NULL? If geometry columns are in the list, then that would cause failure. Your question would be aided by a "context diff" of the pretty-printed before and after documents (the lines around the area where changes occurred, as displayed by diff -c)

– Vince
Jul 19 '18 at 3:21










1 Answer
1






active

oldest

votes


















0














I compared my input and output xml files and element tree is not parsing the file correctly. It is leaving out tags and backslashes and adding spaces where they should not be.



I tried using lxml package and it works.






share|improve this answer
























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "79"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f289913%2fedit-xml-from-geodatabase-using-python-element-tree%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I compared my input and output xml files and element tree is not parsing the file correctly. It is leaving out tags and backslashes and adding spaces where they should not be.



    I tried using lxml package and it works.






    share|improve this answer




























      0














      I compared my input and output xml files and element tree is not parsing the file correctly. It is leaving out tags and backslashes and adding spaces where they should not be.



      I tried using lxml package and it works.






      share|improve this answer


























        0












        0








        0







        I compared my input and output xml files and element tree is not parsing the file correctly. It is leaving out tags and backslashes and adding spaces where they should not be.



        I tried using lxml package and it works.






        share|improve this answer













        I compared my input and output xml files and element tree is not parsing the file correctly. It is leaving out tags and backslashes and adding spaces where they should not be.



        I tried using lxml package and it works.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jul 19 '18 at 19:51









        cmittcmitt

        62




        62






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f289913%2fedit-xml-from-geodatabase-using-python-element-tree%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Щит и меч (фильм) Содержание Названия серий | Сюжет |...

            Венесуэла на летних Олимпийских играх 2000 Содержание Состав...

            Meter-Bus Содержание Параметры шины | Стандартизация |...