cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

CSV to XML with repetitive xml nodes

deepak_shaw
Contributor

Hi,
Iโ€™m trying to create a pipeline which suppose to create an xml file out of a CSV file.

CSV file looks like -
|ProductCode|ProductName|Price|Country|
|A001|DellLaptop|$400|US|
|A001|DellLaptop|$500|AU|
|A001|DellLaptop|$550|EU|

XML output should be -

<?xml version="1.0" encoding="UTF-8"?> US $400 AU $500 EU $550 [XML file attached as its not coming well in the question well..] Thanks for your answer, Deepak Shaw [Product.zip|attachment](upload://7NZiA8X09vabLf1eK3iLKeLDU5f.zip) (203 Bytes)
1 ACCEPTED SOLUTION

Just a small change in your Mapper needed:

image

That will output JSON like:

[{
	"Invoice": {
		"@xmlns:cac": "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2",
		"@xmlns:cbc": "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2",
		"@xmlns": "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2",
		"cbc:CustomizationID": "urn:cen.eu:en16931:2017#conformant#urn:fdc:peppol.eu:2017:poacc:billing:international:aunz:3.0",
		"cbc:ProfileID": "urn:fdc:peppol.eu:2017:poacc:billing:01:1.0",
		"cbc:ID": "PRP100418",
		"cbc:IssueDate": "29/04/2022",
		"cbc:DueDate": "6/05/2022",
		"cbc:InvoiceTypeCode": "380",
		"cbc:Note": "110535 - DAF - XRef607 ICT Services - CRM Developer",
		"cbc:DocumentCurrencyCode": "AUD",
		"InvoiceLines": [{
			"LineNumber": "1",
			"Tax": "700"
		}, {
			"LineNumber": "2",
			"Tax": "700"
		}],
		"ABNValue": "ABN 31 100 103 268"
	}
}]

which the XML Formatter will turn into:

<?xml version="1.0" encoding="UTF-8"?>
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
   <cbc:CustomizationID>urn:cen.eu:en16931:2017#conformant#urn:fdc:peppol.eu:2017:poacc:billing:international:aunz:3.0</cbc:CustomizationID>
   <cbc:ProfileID>urn:fdc:peppol.eu:2017:poacc:billing:01:1.0</cbc:ProfileID>
   <cbc:ID>PRP100418</cbc:ID>
   <cbc:IssueDate>29/04/2022</cbc:IssueDate>
   <cbc:DueDate>6/05/2022</cbc:DueDate>
   <cbc:InvoiceTypeCode>380</cbc:InvoiceTypeCode>
   <cbc:Note>110535 - DAF - XRef607 ICT Services - CRM Developer</cbc:Note>
   <cbc:DocumentCurrencyCode>AUD</cbc:DocumentCurrencyCode>
   <InvoiceLines>
      <LineNumber>1</LineNumber>
      <Tax>700</Tax>
   </InvoiceLines>
   <InvoiceLines>
      <LineNumber>2</LineNumber>
      <Tax>700</Tax>
   </InvoiceLines>
   <ABNValue>ABN 31 100 103 268</ABNValue>
</Invoice>

which is what I believe you wanted.

View solution in original post

19 REPLIES 19

Hi @robin,
I could able to follow your suggestions and created a sample pipeline (attached)
However, it creates xml output bit different

<?xml version='1.0' encoding='UTF-8'?>
<Invoice
    xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
    xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
    xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
    <cbc:CustomizationID>urn:cen.eu:en16931:2017#conformant#urn:fdc:peppol.eu:2017:poacc:billing:international:aunz:3.0</cbc:CustomizationID>
    <cbc:ProfileID>urn:fdc:peppol.eu:2017:poacc:billing:01:1.0</cbc:ProfileID>
    <cbc:ID>PRP100418</cbc:ID>
    <cbc:IssueDate>29/04/2022</cbc:IssueDate>
    <cbc:DueDate>6/05/2022</cbc:DueDate>
    <cbc:InvoiceTypeCode>380</cbc:InvoiceTypeCode>
    <cbc:Note>110535 - DAF - XRef607 ICT Services - CRM Developer</cbc:Note>
    <cbc:DocumentCurrencyCode>AUD</cbc:DocumentCurrencyCode>
    <InvoiceLines>
        <LineNumber>1</LineNumber>
        <LineNumber>2</LineNumber>
        <Tax>700</Tax>
        <Tax>700</Tax>
    </InvoiceLines>
    <ABNValue>ABN 31 100 103 268</ABNValue>
</Invoice>

Can you please suggest the fix?
Csv2Xml_2022_05_19.slp (17.0 KB)

Thanks,
Deepak.

Sorry, a fix to what? I donโ€™t understand what the issue is.

Hi @robin ,
I would like the child node should appear like :

Just a small change in your Mapper needed:

image

That will output JSON like:

[{
	"Invoice": {
		"@xmlns:cac": "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2",
		"@xmlns:cbc": "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2",
		"@xmlns": "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2",
		"cbc:CustomizationID": "urn:cen.eu:en16931:2017#conformant#urn:fdc:peppol.eu:2017:poacc:billing:international:aunz:3.0",
		"cbc:ProfileID": "urn:fdc:peppol.eu:2017:poacc:billing:01:1.0",
		"cbc:ID": "PRP100418",
		"cbc:IssueDate": "29/04/2022",
		"cbc:DueDate": "6/05/2022",
		"cbc:InvoiceTypeCode": "380",
		"cbc:Note": "110535 - DAF - XRef607 ICT Services - CRM Developer",
		"cbc:DocumentCurrencyCode": "AUD",
		"InvoiceLines": [{
			"LineNumber": "1",
			"Tax": "700"
		}, {
			"LineNumber": "2",
			"Tax": "700"
		}],
		"ABNValue": "ABN 31 100 103 268"
	}
}]

which the XML Formatter will turn into:

<?xml version="1.0" encoding="UTF-8"?>
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
   <cbc:CustomizationID>urn:cen.eu:en16931:2017#conformant#urn:fdc:peppol.eu:2017:poacc:billing:international:aunz:3.0</cbc:CustomizationID>
   <cbc:ProfileID>urn:fdc:peppol.eu:2017:poacc:billing:01:1.0</cbc:ProfileID>
   <cbc:ID>PRP100418</cbc:ID>
   <cbc:IssueDate>29/04/2022</cbc:IssueDate>
   <cbc:DueDate>6/05/2022</cbc:DueDate>
   <cbc:InvoiceTypeCode>380</cbc:InvoiceTypeCode>
   <cbc:Note>110535 - DAF - XRef607 ICT Services - CRM Developer</cbc:Note>
   <cbc:DocumentCurrencyCode>AUD</cbc:DocumentCurrencyCode>
   <InvoiceLines>
      <LineNumber>1</LineNumber>
      <Tax>700</Tax>
   </InvoiceLines>
   <InvoiceLines>
      <LineNumber>2</LineNumber>
      <Tax>700</Tax>
   </InvoiceLines>
   <ABNValue>ABN 31 100 103 268</ABNValue>
</Invoice>

which is what I believe you wanted.

Hi @robin,
Thanks for your helpโ€ฆ really appriciated.
Regards,
Deepak.