Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Posting on Qlik Community is temporarily paused for some users. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
_AnonymousUser
Specialist III
Specialist III

tXMLMap convert attribute to name/value element

Hi, I am trying to use TOS for Data Integration to convert an input XML into another general purpose XML structure much like a name/value structure.
Here is my input XML:
<invoice id="id1" no="no1" date="date1">
<amount>123.45</amount>
<due>2013-03-01</due>
<details>
<item>
<description>tran1</description>
<value>value1</value>
</item>
<item>
<description>tran2</description>
<value>value2</value>
</item>
<item>
<description>tran3</description>
<value>value3</value>
</item>
</details>
</invoice>
Here is my target output XML:
<statement acc="id1" xkey="no1">
<field name="date">date1</field>
<field name="amount">123.45</field>
<field name="due">2013-03-01</field>
<section name="details">
<secion name="item" occ="1">
<field name="description">tran1</field>
<field name="value">value1</field>
</section>
<secion name="item" occ="2">
<field name="description">tran2</field>
<field name="value">value2</field>
</section>
<secion name="item" occ="3">
<field name="description">tran3</field>
<field name="value">value3</field>
</section>
</section>
</statement>
My challenge is that I could not find a way to map a source attribute invoice/@date into a target element <field name="date">date1</field> in which the attribute name "date" becomes the name of the element <field> and the attribute value "date1" becaomes the element value.
Any idea how can I achieve this?
Thanks in advance.
Labels (3)
2 Replies
Anonymous
Not applicable

Hi
In this case, there are multiple loop elements in output xml file. The attribute name in the source file will be a fixed attribute value of the element <field> base on the line number, see pic2, here I create a demo job to show how to achieve this kind of requirement with the 'Append the source xml file' feature of tAdvancedFileOutputXML component.
result:
<?xml version="1.0" encoding="ISO-8859-15"?>
<root>
<statement acc="id1" xkey="no1">
<sections name="details">
<section name="item" occ="1">
<field name="description">tran1</field>
<field name="value">value1</field>
</section>
<section name="item" occ="2">
<field name="description">tran2</field>
<field name="value">value2</field>
</section>
<section name="item" occ="3">
<field name="description">tran3</field>
<field name="value">value3</field>
</section>
</sections>
<field name="date">date1</field>
<field name="amount">123.45</field>
<field name="due">2013-03-01</field>
</statement>
</root>

Please email me if you want the job!
Shong
0683p000009MDxg.png 0683p000009MDxl.png
Anonymous
Not applicable

Hi Shong,

 

Can you send me that job to tharanibalan.v@gmail.com

 

Thanks

Tharanibalan