Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: Tim MeagherHi,
Someone might have better information on how to get this working.... however, from what I understand, you can't use multiple
attributeHandler decorators as described in the XMLpy File tutorial where it states:
the attributeHandler can only be used on a single function
Therefore, I think that the best way around this is to simply process the element
rootElement and retrieve the attributes and sub-elements from this
rootElement.
If
rootElement is very large (e.g. contains a lot of sub-elements), then a different approach may be necessary to ensure that the entire contents of
rootElement are not loaded into memory.
However, assuming that this is not a problem, then you should be able to use the following code to read all the data from the XML snippet you have attached:
def Initialize():
metadata = {}
metadata['SequenceNumber_'] = 123
metadata['CreationDate_'] = "123"
metadata['ElementCount_'] = 1
metadata['Value1'] = "V1"
metadata['Value2'] = "V2"
setMetadata(metadata)
@elementHandler('/rootElement')
def RootHandler(element):
data = {}
data['SequenceNumber_'] = element.sequenceNumber
data['CreationDate_'] = element.creationDate
data['ElementCount_'] = element.elementCount
data['Value1'] = element.dataElement1
data['Value2'] = element.dataElement2
outputRecord(data,0)
In this sample, the
Initialize method will simply set the metadata to ensure that the correct types are used.
The
RootHandler method then handles the
rootElement element.
The
sequenceNumber,
creationDate and
elementCount attributes are obtained from this element - as are the sub-elements
dataElement1 and
dataElement2.
Then the record is written with this data.
Hope this helps some,
Tim.