xml schemas with elements with unbounded maximum occurrence

One Star

xml schemas with elements with unbounded maximum occurrence

Hi,
I would like to do a VERY SIMPLE job that reads an XML file and writes it as is to another XML file.
The trick is in that the schema allows for multiple elements to have multiple occurrencies.
The sample schema and file I am using are as follows:
-------------------- BankAccount.xsd --------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="collection">
<xs:complexType>
<xs:sequence>
<xs:element name="account">
<xs:complexType>
<xs:sequence>
<xs:element name="ownerSurname" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="outcome" type="xs:decimal" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="income" type="xs:decimal" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

-------------------------------------accounts.xml -----------------------------------------------
<collection>
<account>
<ownerSurname>Smith</ownerSurname>
<outcome>120.0</outcome>
<outcome>135.0</outcome>
<outcome>20.0</outcome>
<income>1120.0</income>
<income>35.0</income>
</account>
</collection>

-------------------------------------------------------------------------------------------------
As you can see the schema is very simple, but I can't get what I want out.
Playing around with grouping and setting loop element I can only achieve to get all outcomes and one only income, or vice-versa.
How do I manage to get both all outcomes and incomes?
Thanks a lot, Eduardo
One Star

Re: xml schemas with elements with unbounded maximum occurrence

I think I found the way to do it. I'll share. If anyone knows of a better way though, please let me know.
The way I solved it is:
- identify each element that may have multiple occurrencies (income and outcome in the example).
- Set up a tFileInputXML component for each of these.
- Set their LoopXPath query to point at these fields (income and outcome in the example).
- In the Mapping area extract each of the fields that DO NOT HAVE MULTIPLE OCCURRENCIES, plus the field pointed by the loop xpath query. (in the example, when setting the tFileInputXML component that has LoopXpath query set to point to outcome, map the fields ownerSurname and outcome, while when setting the one for income map the fields ownerSurname and income).
- Take all the flows coming from these files and direct them as input for a tFileOutputMSXML.
- In this component, for each incoming schema, set up an XML tree that exactly reflects the "sub-schema" that contains its fields, setting up the parent node of the Loop Xpath query as a "group element", while the xpath query field as loop element.
This should work (it works with me).
I will include images for clarity
One Star

Re: xml schemas with elements with unbounded maximum occurrence

looks like the same procedure must be applied also to each optional field.
this means that for large xml files this is a very tedious and error prone method. isn't there any quicker and more controllable way to do this?