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

            Export of reprojected layer from GEE fails Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Iterate over features and years to export images for each feature-yearEarth engine reproject: why does reprojecting a pixel at 30m scale gives me pixels with an area of ~550?Exporting slope raster for entire country in GEEGEE Landsat SR year composite // mask cloud / shadow out w/ other method than quality pixel"export region contains no valid (un-masked) pixels - Google Earth EgineGoogle Earth Engine, how to distinguish between rivers/streams and ponds/lakes in a water maskPython script tool fails when processing rainfall data from Google Earth EngineGoogle Earth Engine Error: Number of pixels requested from Image.load exceeds the maximum allowedCloudfree images in small area from Sentinel-2Using Image exportToDrive in Google Earth Engine?

            Crop image to path created in TikZ? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Crop an inserted image?TikZ pictures does not appear in posterImage behind and beyond crop marks?Tikz picture as large as possible on A4 PageTransparency vs image compression dilemmaHow to crop background from image automatically?Image does not cropTikzexternal capturing crop marks when externalizing pgfplots?How to include image path that contains a dollar signCrop image with left size given

            Creating closest line along the point''s azimuth using PostgreSQL Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Drawing line between points at specific distance in PostGIS?How to efficiently find the closest point over the dateline?How to find the nearest point by using PostGIS function?PostGIS nearest point with LATERAL JOIN in PostgreSQL 9.3+Creating a table and inserting selected streets using plpgsql functionsCreating a table that stores Distances and other columnSaving select query results (year wise) from PostgreSQL/PostGIS to text filesWhat is the information behind this geometry?How to give start and end vertex ids dynamically in pgr_dijkstra?Point to Polygon nearest distance DS_distance is not using geography index & knn <-> or <#> does not give result in orderLine to point conversion with start point and end point detection?