1

I'm trying to update the WebCapabilties to allow uploads for a service definition. I've followed the instructions from ESRI's website, but when I try to set the keyValue.nextSibling.firstChild.data equal to "Uploads" I get the following error message...

AttributeError: 'NoneType' object has no attribute 'data'

doc = DOM.parse(sdDraft)
configProps = doc.getElementsByTagName('Info')[0]
propArray = configProps.firstChild
propSets = propArray.childNodes
for propSet in propSets:
    keyValues = propSet.childNodes
    for keyValue in keyValues:
        if keyValue.tagName == 'Key':
            if keyValue.firstChild.data == "WebCapabilities":
                keyValue.nextSibling.firstChild.data = "Uploads"

Inside the XML, I can see the what needs to be updated.

<Key>WebCapabilities</Key><Value xsi:type='xs:string'></Value>

Needs to be...

<Key>WebCapabilities</Key><Value xsi:type='xs:string'>Uploads</Value>

If I manually update the value, I can see the firstChild.data value, if I don't, then firstChild is set to None, and I can't access the .data property of the firstChild.

  • please post your file content what you want to change rahter that a line only.Whereas the overall structure of the tree is understood. – SIslam Dec 22 '16 at 6:16
  • I'm not sure if it's an ESRI thing, or a python thing, but the entire document is on one line. Posting it would just be one giant linewrapped mess, which is why I just cut out the small piece that I'm trying to update. I'm sure those familiar with SDDrafts know what I'm talking about. I hope that this is a simple matter of knowing the right function to use in order to add data to a blank firstChild node. – RobertY Dec 22 '16 at 16:14
  • No matter how long the file is just pretty format that, post the content here and make this question completely understandable for all. There are many ways to xml tree traversal and modification but one needs to have the what to play with at first. – SIslam Dec 22 '16 at 16:25
  • This is just academic for me now, I wrote a script to update the property after the service is published, rather than trying to modify the sddraft. I'd be interested in knowing what I'm missing, but I'm not going to post a giant xml document in here. – RobertY Dec 22 '16 at 17:37
  • Ah! but how to write script or understanding your script needs to have the file structure in head beforehand at least for noobs like me! You need not to post the giant xml rather just the understandable(with some before and some after) structure of what you want to modify Well then hope someone with better understanding will help here! – SIslam Dec 22 '16 at 18:16
0

You need to check for None.

if val is not None:

Otherwise you will see this, some of the Key values or properties nodes can be None.

So:

doc = DOM.parse(sdDraft)
configProps = doc.getElementsByTagName('Info')[0]
propArray = configProps.firstChild
propSets = propArray.childNodes
for propSet in propSets:
    keyValues = propSet.childNodes
    for keyValue in keyValues:
        if (keyValue.tagName == 'Key' and
            keyValue.nextSibling.firstChild and
            keyValue.firstChild.data == "WebCapabilities"
        ):
            keyValue.nextSibling.firstChild.data = "Uploads"

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.