Changeset 5628 for anuga_core/source/anuga/utilities/xml_tools.py
- Timestamp:
- Aug 8, 2008, 9:28:34 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/utilities/xml_tools.py
r5162 r5628 239 239 fid = xml 240 240 241 dom = parse(fid) 242 243 ## try: 244 ## dom = parse(fid) 245 ## except Exception, e: 246 ## # Throw filename into dom exception 247 ## msg = 'XML file "%s" could not be parsed: ' %fid.name 248 ## msg += str(e) 249 ## raise Exception, msg 250 251 return dom2object(dom) 241 try: 242 dom = parse(fid) 243 except Exception, e: 244 # Throw filename into dom exception 245 msg = 'XML file "%s" could not be parsed.\n' %fid.name 246 msg += 'Error message from parser: "%s"' %str(e) 247 raise Exception, msg 248 249 try: 250 xml_object = dom2object(dom) 251 except Exception, e: 252 msg = 'Could not convert %s into XML object.\n' %fid.name 253 msg += str(e) 254 raise Exception, msg 255 256 return xml_object 252 257 253 258 … … 258 263 259 264 value = [] 265 textnode_encountered = None 260 266 for n in node.childNodes: 261 267 262 268 if n.nodeType == 3: 263 269 # Child is a text element - omit the dom tag #text and 264 270 # go straight to the text value. 265 271 272 # Note - only the last text value will be recorded 273 266 274 msg = 'Text element has child nodes - this shouldn\'t happen' 267 275 assert len(n.childNodes) == 0, msg … … 273 281 continue 274 282 275 value = x283 textnode_encountered = value = x 276 284 else: 277 285 # XML element 286 287 288 if textnode_encountered is not None: 289 msg = 'A text node was followed by a non-text tag. This is not allowed.\n' 290 msg += 'Offending text node: "%s" ' %str(textnode_encountered) 291 msg += 'was followed by node named: "<%s>"' %str(n.nodeName) 292 raise Exception, msg 293 278 294 279 295 value.append(dom2object(n))
Note: See TracChangeset
for help on using the changeset viewer.