Home Page › Forums › BizTalk 2004 – BizTalk 2010 › Looping XML to Flat File Mapping
- This topic has 3 replies, 1 voice, and was last updated 9 years, 2 months ago by
community-content.
-
AuthorPosts
-
-
May 14, 2010 at 1:36 PM #24701
Hello Everyone
BizTalk newbie here with a mapping problem.
I have a simple XML file that I am trying to map to a flat file schema. The XML has a few single fields and also a repeating complex type while the flat file has the corresponding fields but everything is flattened out. XML has a node that does not repeat with FirstName and LastName under it (we get three repeats). There are three iterations of the name and thus a total of three first and three last names. The flat file has FirstName1, LastName1, FirstName2, LastName2 and so on.
I put “Index” shapes between the XML fields and each of the flat files fields. That worked great and I was a happy guy – as long as we got all 6 inputs. The problem is if an iteration of the XML is missing a tag – like LastName – it throws off the indexing. Example: LastName1 is missing as there is no value – our subject is “Madonna” or “Sting” I guess. What happens is that BizTalk assigns the first index to LastName2 in the XML and puts it in LastName1 of the flat file.
Loops don’t want to hook up for some reason.
I have tried iterations to equals to value shapes and I get the same thing. I am trying to avoid flattening the input XML as I will probably have the same problem there.
Is this better done in an orchestration? I think they want it in a map in the pipeline. I can’t help but think that this is something that has been done a zillion times in XML to mainframe work.
All help is greatly appreciated.
Thanx,
– Ziggy –
-
May 17, 2010 at 9:24 AM #24709
Hi Ziggy,
Instead of a map, how about just using XPath and XQuery assignments in an Expression shape to achieve what you want? Just a thought and a suggestion…
Daniel.
-
May 17, 2010 at 2:48 PM #24715
Ziggy,
Is the XML schema in below format?
<Person><FN><LN></Person> where Person loops. And do the FN and LN in the flat file occur a finite number of times?
If yes, you can add a condition to look for the incoming node name and index and only then map to LN/FN
You can also look add XSLT snippets using the scripting functiod. Orchestration won’t be required.
Hope this helps.
– JC
-
-
May 18, 2010 at 7:26 AM #24718
What a difference it makes to take a weekend and come back to a problem! Well – I found the problem and is looks like a good “Lessoned Learned”. As it turns out – using the index shape in the map was correct. That was what the Microsoft consultatnt here was doing and it worked for him. I had been trying it and all sorts of versions for two days and no luck. The reason it was not working for me was that the incoming XSD was wrong! The first problem was that I had not nested FN and LN correctly under Name, So – the three instances of F/L Name were all under one instance of Name. It should have been three instances of Name with each having one set of First and Last Name. I discovered this by generating some more instances of the XML from the schema in BizTalk and looking at it. The XML I was feeding the map was hand made and correct – but the XSD for it could not understand it.
The second problem was in the destination flat file being created. The second and third instance of name was not getting the values for the tags extracted. The destination XML, which was a flat file schema with the occurs flattened, was being built with empty tags. I had built the destination in BizTalk, but at some point modified it in XML Spy and refreshed it in BizTalk. Apparently Spy created Record Elements of the “Any Type”. BizTalk did not like that. After replacing the second and third tags in the destination schema it worked just great.
So, the moral of the story and lesson learned. If what you are doing should work and does not – start checking the infrastructure! Check the incoming XSD and XML (former was problem for me). Also, XML Spy can be a great tool – but look for times that it won’t feed BizTalk what it wants.
-
-
AuthorPosts
- The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.