Changeset 5628


Ignore:
Timestamp:
Aug 8, 2008, 9:28:34 AM (16 years ago)
Author:
ole
Message:

Added error check in xml_tools to catch text nodes followed by non-text nodes.
This was in response to an error in one of the license files (not yet fixed).

Location:
anuga_core/source/anuga
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/shallow_water/urs_ext.c

    r5612 r5628  
    22gcc -fPIC -c urs_ext.c -I/usr/include/python2.5 -o urs_ext.o -Wall -O
    33gcc -shared urs_ext.o  -o urs_ext.so
    4 */
    5 
    6 /*
    7 This file was reverted from changeset:5484 to changeset:5470 on 10th July
    8 by Ole.
    94*/
    105
     
    3025
    3126static long numDataMax=0;
     27
     28
     29/*The MUX file format
     30
     31
     32 */
     33
     34
    3235
    3336/////////////////////////////////////////////////////////////////////////
     
    294297    }
    295298
     299   
    296300    // Store time resolution and number of timesteps   
    297301    // These are the same for all stations as tested above, so
     
    394398    muxData = (float*) malloc(numDataMax*sizeof(float));
    395399   
    396     /* Loop over all sources */
     400    // Loop over all sources
    397401    for (isrc = 0; isrc < numSrc; isrc++)
    398402    {
     
    437441                          total_number_of_stations,
    438442                          number_of_time_steps,
    439                           mytgs0[ista].ig,
     443                          mytgs0[ista].ig, // Grid number (if -1 fill with zeros)
    440444                          fros_per_source,
    441445                          lros_per_source,
  • anuga_core/source/anuga/utilities/data_audit.py

    r5195 r5628  
    257257    """
    258258
     259    if verbose:
     260        print 'Parsing', license_filename
     261       
    259262    doc = xml2object(license_filename)
    260263   
  • anuga_core/source/anuga/utilities/xml_tools.py

    r5162 r5628  
    239239        fid = xml
    240240
    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
    252257
    253258
     
    258263
    259264    value = []
     265    textnode_encountered = None
    260266    for n in node.childNodes:
    261 
     267   
    262268        if n.nodeType == 3:
    263269            # Child is a text element - omit the dom tag #text and
    264270            # go straight to the text value.
    265 
     271           
     272            # Note - only the last text value will be recorded
     273           
    266274            msg = 'Text element has child nodes - this shouldn\'t happen'
    267275            assert len(n.childNodes) == 0, msg
     
    273281                continue
    274282           
    275             value = x
     283            textnode_encountered = value = x
    276284        else:
    277285            # 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           
    278294
    279295            value.append(dom2object(n))
Note: See TracChangeset for help on using the changeset viewer.