1

I would like adding a new parameter into my sddraft, the value of "cacheControlMaxAge". For this, I have the following code that modifies the value of already existing parameters :

import xml.dom.minidom as dom
doc = dom.parse(r"Z:\secret_folder\service.sddraft")
configProps = doc.getElementsByTagName('ConfigurationProperties')[0]
configPropArray = configProps.firstChild
configPropSets = configPropArray.childNodes
for configPropSet in configPropSets:
    configPropKeyValues = configPropSet.childNodes
    for configPropKeyValue in configPropKeyValues:
        if configPropKeyValue.tagName == 'Key':
            if configPropKeyValue.firstChild.data == 'cacheControlMaxAge':
                configPropKeyValue.nextSibling.firstChild.data = 604800
                print "OK"
            else:
                print "KO"

However, it seems that the parameter does not exist :

KO

If I am wrong with variable name/parameter, how do I add this parameter in the sddraft ?

  • How do you create the sddraft, how are you planning to use it, and why do you need this extra parameter? – Alex Tereshenkov Mar 15 '18 at 9:32
  • I created the sddraft file with the python function arcpy.mapping.CreateMapSDDraft. – Rudymil1 Mar 15 '18 at 10:41
  • I planned to use it in order to generate a sd file using the python function arcpy.StageService_server. – Rudymil1 Mar 15 '18 at 10:45
  • I need this parameter to increase the caching time of query responses for a week. – Rudymil1 Mar 15 '18 at 10:47
1

Finally, I found a solution to the problem described above. There it is :

import xml.dom.minidom as dom

doc = dom.parse(r"Z:\secret_folder\service.sddraft")

PropertySetProperty_balise = doc.createElement("PropertySetProperty")  # creation d une balise PropertySetProperty
PropertySetProperty_balise.setAttribute("xsi:type", "typens:PropertySetProperty")  # ajout de l attribut xsi:type="typens:PropertySetProperty" a la balise PropertySetProperty
key_balise = doc.createElement("Key")  # creation d une balise Key
key_value = doc.createTextNode("cacheControlMaxAge")  # creation d un texte de valeur "cacheControlMaxAge"
key_balise.appendChild(key_value)  # insertion de la balise texte de valeur "cacheControlMaxAge" dans la balise Key
value_balise = doc.createElement("Value")  # creation d une balise Value
value_balise.setAttribute("xsi:type", "xs:double")  # parametrage du type de la balise Value
value_value = doc.createTextNode(cacheControlMaxAge)  # creation d un texte de valeur numerique cacheControlMaxAge
value_balise.appendChild(604800)  # insertion de la balise texte de valeur numerique cacheControlMaxAge dans la balise Value
PropertySetProperty_balise.appendChild(key_balise)  # insertion de la balise Key dans la balise PropertySetProperty
PropertySetProperty_balise.appendChild(value_balise)  # insertion de la balise Value dans la balise PropertySetProperty

configProps = doc.getElementsByTagName('ConfigurationProperties')[0]
configPropArray = configProps.firstChild
configPropArray.appendChild(PropertySetProperty_balise)  # insertion de la balise PropertySetProperty dans la balise PropertyArray
configPropSets = configPropArray.childNodes
for configPropSet in configPropSets:
    configPropKeyValues = configPropSet.childNodes
    for configPropKeyValue in configPropKeyValues:
        if configPropKeyValue.tagName == 'Key':
            if configPropKeyValue.firstChild.data == 'cacheControlMaxAge':
                print configPropKeyValue.nextSibling.firstChild.data
            else:
                print "KO"

And I get :

604800

In fact I manually created all the necessary tags, without forgetting to configure their type (to keep a valid sddraft) then I inserted the tags in the right place.

Thanks for your intervention,

Hope this will help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.