Changeset 847


Ignore:
Timestamp:
27/04/06 15:27:43 (13 years ago)
Author:
domlowe
Message:

fixed whitespace issues, namespace issues

Location:
TI02-CSML/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • TI02-CSML/trunk/Scanner/csmllibs/csmlbuilder.py

    r837 r847  
    55from cElementTree import tostring 
    66import csmllibs 
     7 
     8 
     9 
    710 
    811 
     
    116119        #as it is the parent element of all the other elements 
    117120        self.csml.appendChild(self.ds_element)   
    118          
     121     
     122 
     123 
     124 
    119125    def saveFile(self): 
    120126        print "Creating CSML document and saving file" 
     
    122128        csml = self.ds.toXML() 
    123129        #parse and pretty print csml 
    124         self.strCSML= parseString(tostring(csml)).toprettyxml() 
     130        self.strCSML =csmllibs.parser_extra.PrettyPrint(csml) 
    125131        #tidy up elementtree style namespaces 
    126132        self.strCSML=csmllibs.parser_extra.removeInlineNS(self.strCSML) 
     
    132138    def printToScreen(self): 
    133139        print "Print to Screen" 
    134          
    135140        print self.strCSML 
    136141 
  • TI02-CSML/trunk/Scanner/csmllibs/csmlfileextracts.py

    r837 r847  
    6161                    dimValue ='1'  #temporary to fix unlimited problem 
    6262                arrayDescriptor.arraySize=str(dimValue) 
    63      
    6463                #SET filename attribute of file extract 
    6564                arrayDescriptor.fileName = filename 
  • TI02-CSML/trunk/newparser/Parser.py

    r826 r847  
    14021402                else: 
    14031403                    self.uom=frag.text 
    1404                  
    1405                  
    14061404            elif frag.tag == CSML('numericType'): 
    14071405                self.numericType = frag.text 
  • TI02-CSML/trunk/newparser/parser_extra.py

    r839 r847  
    1111 
    1212 
    13 #string manipulation function. may as well go in this file for now. 
     13#some xml/string manipulation functions. may as well go in this file for now: 
     14 
     15#Pretty printing (courtesy of BNL) 
     16def estrip(elem): 
     17        if elem is None: 
     18                return '' 
     19        else: 
     20                return elem.strip() 
     21def PrettyPrint(elem,indent=''): 
     22        #result='%s<%s>%s'%(indent,elem.tag,estrip(elem.text)) 
     23        strAttrib='' 
     24        if elem.attrib != {}: 
     25            for att in elem.attrib: 
     26                strAttrib = strAttrib + ' ' + att + '=' +elem.attrib[att] 
     27        result='%s<%s%s>%s'%(indent,elem.tag,strAttrib,estrip(elem.text)) 
     28        children=len(elem) 
     29        if children: 
     30                copy=indent+'   ' 
     31                for item in elem: 
     32                        result+='\n'+PrettyPrint(item,indent=copy) 
     33                result+='\n%s%s</%s>'%(indent,estrip(elem.tail),elem.tag) 
     34        else: 
     35                result+='</%s>'%(elem.tag) 
     36        return result 
     37 
     38 
     39# fixing up namespaces: 
    1440def removeInlineNS(csmlstring): 
    1541        #  removeInlineNS: function removes "inline" namespaces and declares them as part of the Dataset element. 
     
    2046        'http://www.opengis.net/om': 'om',  'http://www.opengis.net/gml': 'gml','http://ndg.nerc.ac.uk/csml' : 'csml', 'http://www.w3.org/1999/xlink':'xlink'}) 
    2147     
    22         # This is used when parsing a csml document# 
    23         #remove all 
    24         csmlstring=csmlstring.replace(' xmlns:csml="http://ndg.nerc.ac.uk/csml"','') 
    25         csmlstring=csmlstring.replace(' xmlns:xlink="http://www.w3.org/1999/xlink"','') 
    26         csmlstring=csmlstring.replace('xmlns:om="http://www.opengis.net/om"','') 
    27         csmlstring=csmlstring.replace('xsi:schemaLocation="http://ndg.nerc.ac.uk/csml/XMLSchemas/CSMLAppSchema.xsd"','') 
    28         csmlstring=csmlstring.replace('xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"','') 
    29  
     48        #replace any fully qualified namespaces 
     49        csmlstring=csmlstring.replace('{http://www.opengis.net/gml}', 'gml:') 
     50        csmlstring=csmlstring.replace('{http://ndg.nerc.ac.uk/csml}','') 
     51        csmlstring=csmlstring.replace('{http://www.w3.org/1999/xlink}','xlink:') 
     52        csmlstring=csmlstring.replace('{http://www.opengis.net/om}','om:')         
    3053        #remove cmsl: prefixes 
    3154        csmlstring=csmlstring.replace('<csml:','<') 
    3255        csmlstring=csmlstring.replace('</csml:','</') 
    33         #add namespace declarations at top of document, after gml namespace declaration 
    34         csmlstring=csmlstring.replace('xmlns:gml="http://www.opengis.net/gml">', 'xmlns:gml="http://www.opengis.net/gml" xmlns:om="http://www.opengis.net/om" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://ndg.nerc.ac.uk/csml/XMLSchemas/CSMLAppSchema.xsd">') 
    3556         
    36         #this is used when creating a new csml document 
     57        #add namespace declarations at top of document 
     58        csmlstring=csmlstring.replace('<Dataset', '<Dataset xmlns="http://ndg.nerc.ac.uk/csml'  'xmlns:gml="http://www.opengis.net/gml" xmlns:om="http://www.opengis.net/om" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://ndg.nerc.ac.uk/csml/XMLSchemas/CSMLAppSchema.xsd">') 
     59         
     60        #this is only used when creating a new csml document 
    3761        csmlstring=csmlstring.replace('ns0', 'gml') 
    3862        csmlstring=csmlstring.replace('xmlns:ns1', 'xmlns:xlink') 
Note: See TracChangeset for help on using the changeset viewer.