Edit XML from geodatabase using Python element treeError 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

What kind of transistor turns on with 0.2 volts?

Crop image to path created in TikZ?

What is the meaning of "of trouble" in the following sentence?

Correctly defining the return of a procedure

Why is my log file so massive? 22gb. I am running log backups

Why do we use polarized capacitors?

How many letters suffice to construct words with no repetition?

Is this homebrew feat, Beast of Burden, balanced?

Denied boarding due to overcrowding, Sparpreis ticket. What are my rights?

Are cabin dividers used to "hide" the flex of the airplane?

Extreme, but not acceptable situation and I can't start the work tomorrow morning

Is there a way to make member function NOT callable from constructor?

Why is the design of haulage companies so “special”?

aging parents with no investments

Landlord wants to switch my lease to a "Land contract" to "get back at the city"

Why does this relative pronoun not take the case of the noun it is referring to?

What is the command to reset a PC without deleting any files

Why was the "bread communication" in the arena of Catching Fire left out in the movie?

What to wear for invited talk in Canada

How to manage monthly salary

Add an angle to a sphere

I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine

Lied on resume at previous job

What do the Banks children have against barley water?



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






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








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
























  • 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
























  • 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












  • 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

            រឿង រ៉ូមេអូ និង ហ្ស៊ុយលីយេ សង្ខេបរឿង តួអង្គ បញ្ជីណែនាំ

            QGIS export composer to PDF scale the map [closed] Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Print Composer QGIS 2.6, how to export image?QGIS 2.8.1 print composer won't export all OpenCycleMap base layer tilesSave Print/Map QGIS composer view as PNG/PDF using Python (without changing anything in visible layout)?Export QGIS Print Composer PDF with searchable text labelsQGIS Print Composer does not change from landscape to portrait orientation?How can I avoid map size and scale changes in print composer?Fuzzy PDF export in QGIS running on macSierra OSExport the legend into its 100% size using Print ComposerScale-dependent rendering in QGIS PDF output

            PDF-ში გადმოწერა სანავიგაციო მენიუproject page