How can I refer to the order id in the meta data related to items in the below example XML snippet?
<orders>
<order>
<orderid>111ORD</orderid>
<trader>trader</trader>
<items>
<item>
<itemid>2IT</itemid>
<quantity>12</quantity>
</item>
</items>
</order>
</orders>
I am using the XMLExtract components to extract the orders and write them to a CSV and extract the contents of Items and write the order line items to a seperate CSV file, but also want to write the order ID as a field for each item row in the CSV file. How should I set the parentKey in the Mapping element for item in this case? setting it as order.rderid or orders.order.orderid does not work. I also have to refer a field in the parent for children that are nested deeper than in the example I have given above.
Thanks,
TAV
<orders>
<order>
<orderid>111ORD</orderid>
<trader>trader</trader>
<items>
<item>
<itemid>2IT</itemid>
<quantity>12</quantity>
</item>
</items>
</order>
</orders>
I am using the XMLExtract components to extract the orders and write them to a CSV and extract the contents of Items and write the order line items to a seperate CSV file, but also want to write the order ID as a field for each item row in the CSV file. How should I set the parentKey in the Mapping element for item in this case? setting it as order.rderid or orders.order.orderid does not work. I also have to refer a field in the parent for children that are nested deeper than in the example I have given above.
Thanks,
TAV
-
Hello TAV,
your mapping should look likefollows:<Mappings>
<Mapping element="orders">
<Mapping element="order" outPort="0">
<Mapping element="item" outPort="1" generatedKey="oid" parentKey="orderid"/>
</Mapping>
</Mapping>
</Mappings>
Field oid describes order id and belongs to port 1 metadata. Field orderid belongs to port 0 metadata and is read from the input file. -
Hi,
How do I refer fields from a child node in another child node? For example :-
<order>
<orderdata>
<orderid>11ORD</orderid>
</orderdata>
<items>
<item>
<itemid>ITMID</itemid>
<quantity>20</quantity>
</item>
</items>
</order>
If I am writing order data records and item records to 2 different CSV files how can I refer to the order id so I can write it as a field in the item records CSV file. -
Try following mapping: <Mappings>
<Mapping element="order" outPort="0" >
<Mapping element="item" outPort="1" generatedKey="oid" parentKey="orderid"/>
</Mapping>
</Mappings>
For more complicated structure you will have to add artificial key field and fulfil it with sequence value - see sequenceField in XMExtract. Then you can use MergeJoin to join data due to this special field.
Please sign in to leave a comment.
Comments 3