我正在使用ksoap在android應用程序和包含以下發布的文件的python服務器之間進行通信。我正在嘗試檢索發佈的XML文件中的所有值。但我不斷收到,AttributeError: 'NoneType' object has no attribute 'nodeValue'
。任何人都可以告訴我代碼有什麼問題,因爲我試圖調試錯誤,但仍然沒有做到。AttributeError:'NoneType'對象沒有屬性'nodeValue'
部分XML文件(僅MacFilterList和地圖節點可以爲空):
<ProfileList>
<Profile>
<ProfileName>Lab1</ProfileName>
<Owner>admin</Owner>
<Map>Lab</Map>
<Visible>True</Visible>
<MacFilterList>
<string>00:14:BF:9F:5D:3A</string>
<string>00:14:BF:9F:5D:52</string>
<string>00:14:BF:9F:5D:37</string>
<string>00:14:BF:9F:5D:43</string>
</MacFilterList>
</Profile>
.
.
</ProfileList>
soapAPI.py(PROFILE_XML
指XML文件的文件名):
def __init__(self):
self.profileFile = Config.PROFILE_XML
self.profile = XML_ProfileDataStore()
self.profile.LoadXMLFile(self.profileFile)
.
.
def GetAllProfileData(self):
self.profileFile = Config.PROFILE_XML
self.profile.LoadXMLFile(self.profileFile)
result = self.profile.GetAllProfileData()
return result
profileData.py(其中類別XML_ProfileDataStore
是):
def GetAllProfileData(self):
#Get a node list containing nodes with name Location
ProfileList = self.XMLdoc.getElementsByTagName('Profile')
NumArgCheck = 0
profiles=""
#For each location node in list
for profileNode in ProfileList:
#For each child nodes in Location node, compare the XY coordinates
for ChildNode in profileNode.childNodes:
#If child node has profile name profile_name
if (cmp(ChildNode.nodeName, 'ProfileName') == 0):
NumArgCheck += 1
profiles = profiles + ChildNode.firstChild.data + ","
ChildNode = ChildNode.nextSibling
profiles = profiles + ChildNode.firstChild.nodeValue + ","
ChildNode = ChildNode.nextSibling
profiles = profiles + ChildNode.firstChild.nodeValue + ","
ChildNode = ChildNode.nextSibling
profiles = profiles + ChildNode.firstChild.nodeValue
ChildNode = ChildNode.nextSibling
for child in ChildNode.childNodes:
profiles = profiles + "," + child.firstChild.nodeValue
profiles = profiles+";"
return profiles
一些在XML文件中的元素的進口部分是空元素,和 。然而,在我執行一些編碼來檢查這種情況後,錯誤仍然存在。而且我還在服務器中創建了一個.py文件來檢索數據,而不是使用我能夠這樣做的Android客戶端應用程序,但不是應用程序。 –
user918197