on 12-09-2010 11:44 AM
Hello everybody!
This is the first time I post to this forum.
I'm facing some difficulty with a message mapping.
Below is the structure of the source message:
<J_1B_NFE_XML_OUT> 1..1
<XML_ADI> 0..1
<item> 0..unbounded
<DOCNUM> 0..1
<ITMNUM> 0..1
<NDI> 0..1
<NADICAO> 0..1
<NSEQADIC> 0..1
<CFABRICANTE> 0..1
<VDESCDI> 0..1
</item>
</XML_ADI>
<XML_ITEM_TAB> 0..1
<item> 0..unbounded
<ITMNUM> 0..1
<NITEM> 0..1
</item>
</XML_ITEM_TAB>
</J_1B_NFE_XML_OUT>
And now the target message:
<NFe> 1..1
<infNFe> 1..1
<det> 1..990
<@nitem>
<adi> 1..unbounded
<nadicao> 1..1
<nSeqAdic> 1..1
<cFabricante> 1..1
<vDescDI> 0..1
</adi>
</det>
</infNFe>
</NFe>
I simplified both structures, leaving only the important part.
Basically, for each "item" ocurrence of XML_ITEM_TAB from the source message, I need to create the node det in the target message. Also, for each item, I need to create 1..n of the "adi" node, based on XML_ADI node from source message.
Example:
Let's say I have this as the source message:
<J_1B_NFE_XML_OUT>
<XML_ADI>
<item>
<DOCNUM>0000035992</DOCNUM>
<ITMNUM>000010</ITMNUM>
<NDI>09/0001570</NDI>
<NADICAO>001</NADICAO>
<NSEQADIC>001</NSEQADIC>
<CFABRICANTE>CABOT</CFABRICANTE>
<VDESCDI>0</VDESCDI>
</item>
<item>
<DOCNUM>0000035992</DOCNUM>
<ITMNUM>000010</ITMNUM>
<NDI>09/0001570</NDI>
<NADICAO>001</NADICAO>
<NSEQADIC>002</NSEQADIC>
<CFABRICANTE>CABOT</CFABRICANTE>
<VDESCDI>0</VDESCDI>
</item>
<item>
<DOCNUM>0000035992</DOCNUM>
<ITMNUM>000020</ITMNUM>
<NDI>09/0001570</NDI>
<NADICAO>001</NADICAO>
<NSEQADIC>001</NSEQADIC>
<CFABRICANTE>CABOT</CFABRICANTE>
<VDESCDI>0</VDESCDI>
</item>
</XML_ADI>
<XML_ITEM_TAB>
<item>
<ITMNUM>000010</ITMNUM>
<NITEM>001</NITEM>
</item>
<item>
<ITMNUM>000020</ITMNUM>
<NITEM>002</NITEM>
</item>
</XML_ITEM_TAB>
</J_1B_NFE_XML_OUT>
I would like the result to be:
<NFe>
<infNFe>
<det nItem="1">
<adi>
<nAdicao>001</nAdicao>
<nSeqAdic>001</nSeqAdic>
<cFabricante>CABOT</cFabricante>
<vDescDI>0</vDescDI>
</adi>
<adi>
<nAdicao>001</nAdicao>
<nSeqAdic>002</nSeqAdic>
<cFabricante>CABOT</cFabricante>
<vDescDI>0</vDescDI>
</adi>
<det nItem="2">
<adi>
<nAdicao>001</nAdicao>
<nSeqAdic>001</nSeqAdic>
<cFabricante>CABOT</cFabricante>
<vDescDI/>
</adi>
</det>
</infNFe>
</NFe>
The real problem I'm facing is that I can't create the "adi" node for the second item. Can anybody help?
Thanks!
You forgot to include <DI> tag, which can also have multiple occurrences for each item in the <NFe>.
But considering you only have one DI for each item, then it's ok.
You need to map the <XML_ADI>/<items> source tag to the <adi> destination tag.
But you need to do it like this:
<items> -> Remove Context -> UDF -> <adi>
Define an UDF of Context type which runs a for loop over the <items>/<ITMNUM> tag and, whenever the current value is different from the past value, adds a context to the queue. This will only work if you consider that the source <items> tags will always be sorted by <ITMNUM>.
Best regards,
Henrique.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The real problem I'm facing is that I can't create the "adi" node for the second item.
If it is coming for first occurence and not for rest then it is a context issue.
Can try with:
1) increase context of source node....right-click...context...increase to a higher level node (so that all the occurences are considered)
2) Make use of standard functions like RemoveContext, CollapseContext ....examples available on SDN.
Regards,
Abhishek.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.