LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Tabular XML File problem

    Employee
    Posted 05-05-2014 08:08

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: aop

    Hi!

    I'm trying to read XML data using Tabular XML File input. I get it working OK but as I read in multiple files I noticed the node errors with some of my xml files. I get an error saying "Expression value warning. Value for expression [nodeset(/child::purchaseInvoice/child:rganization/child::*/child::text())] returns []." Now I'm trying to understand what's wrong with some of the xml files but based on the error log message I'm not yet quite sure.

    I did check the structure of the files causing the problem but the XML structure seemed corret. However I noticed the files causing the problem are missing line change characters so basically those files have the whole file content on 1 row. Could that cause the node to error?

    However, I can read the data with XMLpy file node and XML Data nodes just fine but as I would prefer to read all elements under certain structure (but no the whole file) I think using XML data node for this is not possible and using xmlpy file would require quite much manual work with defining all the fields manually.


  • 2.  RE: Tabular XML File problem

    Employee
    Posted 05-05-2014 09:33

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Tim Meagher

    Hi,

    The missing newlines shouldn't have an impact on the Tabular XML File node.
    I'm not sure what the problem you're running into there is - maybe someone else has a better idea - in order to figure it out more I'd probably need some representative data sample.

    In any case, with the XML Data node, if I understood correctly, you should be able to get what you want.
    If you have XML like:

    <top>
        <element name="somethingToIgnore"/>
        <record>
            <name>John</name>
            <address>12 something street</address>
            <city name="New York"/>
            <country>US</country>
        </record>
        <record>
            ...
        </record>
        ...
    
    
        <otherElement>
            <otherSubElement attr="true"/>
            ...
        </otherElement>
    </top>
    And the only fields you are interested in are those within the record element under the top element, then you can just rename the Data output to "top.record" and set the "UnmappedFieldBehavior" parameter to "Ignore", then this will do what you want and ignore everything under "otherElement" and "someElement".

    If however, you wanted only to get for instance the top.record.name, and top.record.address fields all on the one output, and ignore everything else under top.record (where you don't know what everything else could be), then this is not currently possible.
    I believe there is already an enhancement request for this sort of functionality, if not, I'll make sure one gets added.

    If, in the above case, you do know which fields you do want to ignore (e.g. top.record.city and top.record.country from the example above), then you can just create additional outputs on the node called "top.record.country" and "top.record.city" - along with the "top.record" output and set the "UnmappedFieldBehavior" parameter to ignore.
    There will still be data produced for the top.record.country and top.record.city outputs in this case, but you can then just ignore those outputs.

    Does this solve the problem for you?

    Tim.


  • 3.  RE: Tabular XML File problem

    Employee
    Posted 05-06-2014 08:20

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: aop

    Regarding the XML Data node I didn't know about renaming the data pin so thanks for help with that. Using your example I would like to read all single elements on the level of top.record (name, address,city,country) but would like skip possible subhierarchies under top.record (e.g. if there would be elements under top.record.hierarhcylevel3 like top.record.hierarhcylevel3.name2 I would like to skip the whole subhierarchy called hierarchylevel3. So I guess this is not possible?

    I'm also trying to achieve my actual goal with the xmlpy node so regarding that I would have another question.
    Currently my xmlpy spec look like the following:
    data = {}
    @elementHandler('purchaseInvoice/invoicePosting/accountingEntry/accountingEntryRow')
    def EntryHandler(element):
    data['ledgerAccountNumber'] = element.ledgerAccountNumber
    outputRecord(data, 0)

    It works ok but I would also need to read in text description which is an attribute of ledgerAccountNumber like the following: <ledgerAccountNumber desc="Account name">1124345</ledgerAccountNumber>
    How can I add it to my xmlpy specification? I tried to play around with it but just couldn't manage to do it.


  • 4.  RE: Tabular XML File problem

    Employee
    Posted 05-06-2014 09:30

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Tim Meagher

    Hey,

    As you identified, what you are talking about doing isn't possible with the XML Data node in the way you want.
    However, you can create a separate node output "top.record.hierarchyLevel3" and just ignore the data produced on that output.
    The data will still be parsed (actually - regardless of the mechanism used, since it's an XML format, the data will always need to be parsed) and output.
    However, it will not be output to the "top.record" output - so the data produced on that node output should contain what you want.

    For the XMLpy File I think (haven't tried this) that the way you can do what you want is using the following:

    data = {}
    @elementHandler('purchaseInvoice/invoicePosting/accountingEntry/accountingEntryRow')
    def EntryHandler(element):    
    data['ledgerAccountNumber'] = element.ledgerAccountNumber
    data['ledgerAccountNumber.desc'] = element.ledgerAccountNumber.desc
    outputRecord(data, 0)
    
    If the "desc" attribute is only optional and doesn't appear on all ledgerAccountNumber elements, then you may need to use the hasattr function, like:

    if hasattr(element.ledgerAccountNumber, "desc"):
        data['ledgerAccountNumber.desc'] = element.ledgerAccountNumber.desc
    Having said that, even though the XML Data node will be writing more output using the workaround I mentioned above, it might end up still being more efficient than the XMLpy File node.
    The way that the XML Data node is written means that it generally processes data much quicker than the XMLpy File node.

    In any case, I have raised as an enhancement request within our system the ability to exclude parts of the XML hierarchy from the data output within our issue tracking system.
    For your reference, this has been raised as issue LAL-619.

    Regards,
    Tim.