Package pyxsd :: Module pyXSD :: Class PyXSD
[hide private]
[frames] | no frames]

Class PyXSD

source code

object --+
         |
        PyXSD

main class of the program that is in charge of data flow. Has command line support when it is called as a script.

Instance Methods [hide private]
  __init__(self, xmlFileInput, xsdFile=None, xmlFileOutput=False, transformOutputName=None, transforms=[], classFile=None, verbose=False, quiet=False)
This class is init'ed from the command line normally.
  executeAndWriteTransforms(self, rootInstance)
  getSchemaFile(self)
  writeParsedXMLFile(self, rootInstance)
Function to write the xml output after it is parsed.
  parseXSD(self)
Reads the given xsd file and creates a set of classes that corespond to the complex and simple type definitions.
  parseXML(self)
Reads the given xml file in the context of the xsd file.
  generateCorrectSchemaTags(self)
Generates the proper schema information and namespace information for a tag.
  writeXML(self, rootInstance, output)
Sends a pythonic instance tree to the tree writer.
  getClasses(self)
Returns the dictionary of classes created by ElementRepresentative for each type specified in the schema.
  loadClassFromFile(self, classFile)
Loads a file with overlay classes into the class dictionary.
  getXmlTree(self)
Sends the xml file into the ElementTree library's parser.
  getXmlOutputFileName(self)
Creates a default name for xml file that is parsed without any transforms.
  getTransformModuleAndLoad(self, className)
Loads a transform class from its class name.
  transform(self, transforms, root)
Calls the transforms specified by the user.
  getTransformsFileName(self)
Creates a default name for xml file that is written after all of the transforms.
  getSchemaInfo(self, nameOrLocation)
Extracts information from the schemaLocation tag or the noNamespaceSchemaLocation tag.
  makeFullName(self, ns, text)
Makes a string that looks similar to some of the names in ElementTree when it contains namespace information.

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


Properties [hide private]

Inherited from object: __class__


Method Details [hide private]

__init__(self, xmlFileInput, xsdFile=None, xmlFileOutput=False, transformOutputName=None, transforms=[], classFile=None, verbose=False, quiet=False)
(Constructor)

source code 

This class is init'ed from the command line normally. Use this information for uses of pyXSD as a library.

Parameters:

- xmlFileInput- The filename of the xml file to input. Can include path information. Will raise an error if not specified. - xsdFile- The filename/path information for the schema file. Will attempt to use the schemaLocation tag in the xml if not specified. - xmlFileOutput- location for xml output to be sent after it is parsed. Will use a default name if not specified. Will not output if value is set to _No_Output_ - transformOutputName- location of the xml output after transform. Will make default filename if not specified. - transforms- A list containing the transform calls in the order they will be performed. - classFile- The location of the overlay class file. Experimental. - verbose- A boolean value. If set to true, will output more information. - quiet- A boolean value. If set to true, will output less information and errors than normal.

Overrides: object.__init__

executeAndWriteTransforms(self, rootInstance)

source code 
None

getSchemaFile(self)

source code 
None

writeParsedXMLFile(self, rootInstance)

source code 

Function to write the xml output after it is parsed. Called from the __init__.

Parameters:

-rootInstance: The root instance of a tree. Must be formatted in program's tree structure.

parseXSD(self)

source code 

Reads the given xsd file and creates a set of classes that corespond to the complex and simple type definitions.

No parameters.

parseXML(self)

source code 

Reads the given xml file in the context of the xsd file. Produces instances of the above classes. Does validation. returns a a schema instance object.

no parameters

generateCorrectSchemaTags(self)

source code 

Generates the proper schema information and namespace information for a tag. ElementTree leaves the schema information in a form that is not valid XML on its own.

No parameters

writeXML(self, rootInstance, output)

source code 

Sends a pythonic instance tree to the tree writer.

parameters:

  • rootInstance: The root instance of a tree. Must be formatted in program's tree structure.
  • output: The file object to write the tree to.

getClasses(self)

source code 

Returns the dictionary of classes created by ElementRepresentative for each type specified in the schema.

no parameters

loadClassFromFile(self, classFile)

source code 

Loads a file with overlay classes into the class dictionary. Overlay classes add to and override the schema type classes to allow for a user to create their own types without changing the schema file itself. Consider this functionality experimental.

parameters:

  • classFile: A string that specifies the location of a user-created overlay class file

getXmlTree(self)

source code 

Sends the xml file into the ElementTree library's parser. Allows for the program to get the schemaLocation before parsing the xml against the schema.

No parameters.

getXmlOutputFileName(self)

source code 

Creates a default name for xml file that is parsed without any transforms. Uses the name from the inputed xml file.

no parameters

getTransformModuleAndLoad(self, className)

source code 

Loads a transform class from its class name. The file that it is located in must be the same as the className, except the first letter in the filename must be lowercase. The transform must be located in a directory called transforms that is in the installation folder of pyXSD, the directory you called the program from, or in the directory where the xml file is.

parameters:

  • className: A string of the transform class name being called

transform(self, transforms, root)

source code 

Calls the transforms specified by the user. Each transform is loaded into memory by getTransformModuleAndLoad(). The transform class is passed the instance of the root element when it is initialized. The transform object is called with the specified arguements and the new root instance is set to whatever the transform returns, which is usually the root, but it is not required. Any user who uses a transform that does not return the root tree instance should be aware that any transform that uses the root instance will fail to work and raise a fatal error. Transforms add a great amount of power to the program, but users might need to tweak their transform calls and any user-written classes in order to get them to work correctly.

Further documentation is located in the doc/ directory and on the pyXSD website. These documents can help users write transform classes and calls.

Parameters:

  • transforms: a list containing the transform calls in the order that they should be called.
  • root: the root instance of a tree. Must be formatted in program's tree structure.

getTransformsFileName(self)

source code 

Creates a default name for xml file that is written after all of the transforms. Uses the name from the inputed xml file.

no parameters

getSchemaInfo(self, nameOrLocation)

source code 

Extracts information from the schemaLocation tag or the noNamespaceSchemaLocation tag. Depending on the value of parameter nameOrLocation, the function outputs the namespace, schema location, or the tag type. This function is meant for use with other functions to easily grab bits of data that are used in various locations in the program.

parameters:

  • nameOrLocation: a one letter string that is either 'l', 'n', or 't'. If the variable is

'l', the location of the schema is returned. If it is 'n', the namespace is returned, if there is one. 't' returns the tag name to indicate if the xml uses schemaLocation or noNamespaceSchemaLocation

makeFullName(self, ns, text)

source code 

Makes a string that looks similar to some of the names in ElementTree when it contains namespace information.

parameters:

  • ns: a string of the namespace used. For this function, this variable is usually set to a url.
  • text: a string of the name of the tag that the full name is being created for.