Package tlib :: Package base :: Module XmlHelper :: Class XmlHelper
[hide private]
[frames] | no frames]

Class XmlHelper

source code

   object --+    
            |    
Helper.Helper --+
                |
               XmlHelper

Helper class to manipulate the data in Xml format

Instance Methods [hide private]
 
__init__(self, data, schema=None)
Constructor for class
source code
 
validateBySchema(self, schema=None)
Check if Xml string is compliant with schema
source code
 
getRoot(self)
Get the root element of the xml
source code
 
getElementsTextByXPath(self, xpath)
Get all elements' text values using XPath
source code
 
getElementsByXPath(self, xpath)
Get all elements using XPath
source code
 
getElementTextByXPath(self, xpath)
Get the first element text using XPath
source code
 
getElementByXPath(self, xpath)
Get the first element using XPath
source code
 
toString(self, pretty_print=True)
Print Xml data in a nice format
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  _schema = None
  _tree = None

Inherited from Helper.Helper: logger

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, data, schema=None)
(Constructor)

source code 

Constructor for class

Parameters:
  • data - the xml string to be processed (alternatively, it can the location of the xml file)
  • schema - path to the xml schema file
Overrides: object.__init__

validateBySchema(self, schema=None)

source code 

Check if Xml string is compliant with schema

Parameters:
  • schema - path to the xml schema file

    @return (bool) whether schema validation is passed

getRoot(self)

source code 

Get the root element of the xml

Returns:
root element

getElementsTextByXPath(self, xpath)

source code 

Get all elements' text values using XPath

Parameters:
  • xpath - Xpath used to search for elements text
Returns:
all matching elements' text values from Xpath search result in a list

getElementsByXPath(self, xpath)

source code 

Get all elements using XPath

Parameters:
  • xpath - Xpath used to search for elements

    @return : all matching elements from Xpath search result in a list

getElementTextByXPath(self, xpath)

source code 

Get the first element text using XPath

Parameters:
  • xpath - Xpath used to search for elements text

    @return : the first matching element text from Xpath search result

getElementByXPath(self, xpath)

source code 

Get the first element using XPath

Parameters:
  • xpath - Xpath used to search for element

    @return : the first matching element from Xpath search result

toString(self, pretty_print=True)

source code 

Print Xml data in a nice format

Parameters:
  • pretty_print - do you want to be pretty?

    @return : formatted xml string