Changeset 5014 for anuga_core/source/anuga/utilities/xml_tools.py
- Timestamp:
- Feb 8, 2008, 5:29:54 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/utilities/xml_tools.py
r5009 r5014 64 64 65 65 66 def remove_whitespace(s): 67 """Remove excess whitespace including newlines from string 68 """ 69 import string 70 words = s.split() # Split on whitespace 71 72 return string.join(words) 73 74 #return s.replace('\n', '') 75 #s.translate(string.maketrans) 76 66 77 67 78 … … 130 141 s += '<%s>' %self.tag 131 142 if isinstance(self.value, basestring): 132 s += self.value143 s += remove_whitespace(self.value) 133 144 else: 134 145 s += '\n' … … 148 159 This will allow statements such as 149 160 150 assert xmlobject['datafile']['accountable'] == 'Jane Sexton' 151 """ 152 161 assert xmlobject['datafile']['accountable'] == 'Jane Sexton' 162 163 If more than one element matches the given key a list of all 164 matches will be returned 165 """ 166 167 result = [] 153 168 for node in self.value: 154 169 if node.tag == key: 155 170 if isinstance(node.value, basestring): 156 return node.value 171 result.append(str(node.value)) 172 #return node.value 157 173 else: 158 return node 174 result.append(node) 175 #return node 176 177 if len(result) == 0: 178 return None 179 if len(result) == 1: 180 return result[0] 181 if len(result) > 1: 182 return result 183 184 185 def has_key(self, key): 186 found = False 187 for node in self.value: 188 if node.tag == key: 189 found = True 190 191 return found 192 159 193 160 194 def keys(self): … … 202 236 fid = xml 203 237 204 #print fid.read()205 238 dom = parse(fid) 206 239
Note: See TracChangeset
for help on using the changeset viewer.