This post i will show you how to create XML metadata using Talend and simple use of tFileinputXML component.
List of topics covering in this post.
- Simple XMl Parsing using tFileInputXML.
- MetatData Creation.
- XPATH finding.
Prerequisite
- Talend Open Studio
- XML File.
Source XML file for demonstration.
<?xml version="1.0"?>
<PurchaseOrder PurchaseOrderNumber="99503" OrderDate="1999-10-20">
<Address Type="Shipping">
<Name>Ellen Adams</Name>
<Street>123 Maple Street</Street>
<City>Mill Valley</City>
<State>CA</State>
<Zip>10999</Zip>
<Country>USA</Country>
</Address>
<Address Type="Billing">
<Name>Tai Yee</Name>
<Street>8 Oak Avenue</Street>
<City>Old Town</City>
<State>PA</State>
<Zip>95819</Zip>
<Country>USA</Country>
</Address>
<DeliveryNotes>Please leave packages in shed by driveway.</DeliveryNotes>
<Items>
<Item PartNumber="872-AA">
<ProductName>Lawnmower</ProductName>
<Quantity>1</Quantity>
<USPrice>148.95</USPrice>
<Comment>Confirm this is electric</Comment>
</Item>
<Item PartNumber="926-AA">
<ProductName>Baby Monitor</ProductName>
<Quantity>2</Quantity>
<USPrice>39.98</USPrice>
<ShipDate>1999-05-21</ShipDate>
</Item>
</Items>
</PurchaseOrder>
Step 1: Create XML Metadata using Talend.
- Go to the Talend repository Metadata node and right click on File XML .
- Provide valid name for metadata.
- In third Step we have to find out which node should be our XPATH LOOP Expression? for that you can find out the leaf node or last node of XML, in above file <Item> is the leaf node, so we will take that one. see the screen for mapping.
- Just Drag and drop all required columns from XML to see above
- Once column selection completes then Click on preview button to review the extracted result.
- If every thing looks fine then proceed with finish button which will take you to the next screen with generated schema, here you can change data type, column name, length if required.
Now our XML metadata ready to use, then just drag and drop xml schema to job design it will ask two component
- tFileinputXML.
- tExtractXMLField.
For now we will use tFileinputXML to extract XML data, lets drop that.
Connect tlogRow to tFileinputXML component and execute the job you see the result, if result not displayed then repeat above steps.
This post we have created
- XML Metadata
- Simple XML parsing.
- Simple use of tFileinputXML component.