/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Public Attributes
xmlIndex::XmlIndexUpdater Class Reference

List of all members.

Public Member Functions

def __init__
def process
def getIndex
def updateXml
def removeWhitespace

Public Attributes

 oldIndex
 indexUpdate
 newIndex

Detailed Description

XML Index Updater class

Definition at line 245 of file xmlIndex.py.


Constructor & Destructor Documentation

def xmlIndex::XmlIndexUpdater::__init__ (   self,
  oldIndex,
  indexUpdate,
  newIndex 
)

Definition at line 247 of file xmlIndex.py.

00248                                                        :
00249         "Constructor"
00250         self.oldIndex = oldIndex
00251         self.indexUpdate = indexUpdate
00252         self.newIndex = newIndex
00253         return


Member Function Documentation

def xmlIndex::XmlIndexUpdater::process (   self)
Update an existing index with entries from new index

Definition at line 254 of file xmlIndex.py.

00255                      :
00256         """Update an existing index with entries from new index"""
00257         import xml.dom.minidom
00258         currentXml = xml.dom.minidom.parse(self.oldIndex)
00259         xmlUpdate = xml.dom.minidom.parse(self.indexUpdate)
00260         self.removeWhitespace(currentXml)
00261         self.removeWhitespace(xmlUpdate)
00262         currentIndex = self.getIndex(currentXml)
00263         indexUpdate = self.getIndex(xmlUpdate)
00264         self.updateXml(currentIndex,indexUpdate)
00265         writeXml( self.newIndex, currentIndex )
00266         return True

def xmlIndex::XmlIndexUpdater::getIndex (   self,
  xmlDoc 
)
Get the diagnostics index from this XML document

Definition at line 267 of file xmlIndex.py.

00268                               :
00269         """Get the diagnostics index from this XML document"""
00270         diagIndex = None
00271         for child in xmlDoc.childNodes:
00272             if (child.nodeType==child.ELEMENT_NODE
00273                 and child.localName == "diagnostic_index"):
00274                 diagIndex = child
00275                 break
00276         if not diagIndex:
00277             print "XML document has no diagnostic index"
00278         return diagIndex

def xmlIndex::XmlIndexUpdater::updateXml (   self,
  currentElement,
  updateElement 
)
Recursively update XML elements

Definition at line 279 of file xmlIndex.py.

00280                                                       :
00281         """Recursively update XML elements"""
00282         mergeChildren = {}
00283         simpleElements = {}
00284         firstIdElement = None
00285         for child in list(currentElement.childNodes):
00286             #print "processing child: ",child.toxml()
00287             if (child.nodeType==child.ELEMENT_NODE
00288                 and child.hasAttributes()
00289                 and child.hasAttribute('id')):
00290                 # Maintain attributes with IDs, will be updated
00291                 if not firstIdElement == None: firstIdElement = child
00292                 childId = child.attributes['id'].value
00293                 mergeChildren[childId] = child
00294             else:
00295                 simpleElements[child.localName]=child
00296         for child in list(updateElement.childNodes):
00297             if (child.nodeType==child.ELEMENT_NODE
00298                 and child.hasAttribute('id')):
00299                 childId = child.attributes['id'].value
00300                 if mergeChildren.has_key(childId):
00301                     # Merge elements with same IDs
00302                     self.updateXml(mergeChildren[childId], child)
00303                 else:
00304                     # Add element with new ID
00305                     # print "Adding new element: ",childId
00306                     currentElement.appendChild(child)
00307             else:
00308                 if(simpleElements.has_key(child.localName)):
00309                     # Replace this simple node
00310                     replaceChild = simpleElements[child.localName]
00311                     # print "Replacing simple element: ",child.localName
00312                     currentElement.replaceChild(child, replaceChild)
00313                     simpleElements[child.localName] = child
00314                 else:
00315                     # Add new simple node
00316                     # print "Adding new simple element: ",child.localName
00317                     currentElement.insertBefore(child, firstIdElement)
00318         return

def xmlIndex::XmlIndexUpdater::removeWhitespace (   self,
  xmlElement 
)
Recursively remove excess whitespace from 'pretty' xml

Definition at line 319 of file xmlIndex.py.

00320                                           :
00321         """Recursively remove excess whitespace from 'pretty' xml"""
00322         for child in list(xmlElement.childNodes):
00323             if child.nodeType==child.TEXT_NODE:
00324                 cleanText = child.data.strip()
00325                 if cleanText=='':
00326                     xmlElement.removeChild(child)
00327                 else:
00328                     child.data = cleanText
00329             else:
00330                 self.removeWhitespace(child)
00331         return


Member Data Documentation

Definition at line 247 of file xmlIndex.py.

Definition at line 247 of file xmlIndex.py.

Definition at line 247 of file xmlIndex.py.


The documentation for this class was generated from the following file:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:54:09 for RunDiagnostics by doxygen 1.7.4