Neil Thompson

BizTalk | .NET | SQL |

  Home  |   Contact  |   Syndication    |   Login
  15 Posts | 20 Stories | 45 Comments | 55 Trackbacks

News

Article Categories

Archives

Post Categories

Fav BizTalk Blogs

Recently, I had a requirement of generating a very large xml instance (1,000,000 + rows ), and to complicate things I needed to be able to generate unique values over the key feild. True to form, I went to the newsgroups because I was not aware of how to use the "Generate Instance" functionality to accomplish the unique values. Enclosed below is the post and the response (solution follows)


Post

Is there a way for the "Generate Instance" operation in Biztalk to generate an instance of an XML file that also includes UNIQUE values over key fields? My schema enforces a unique contraint on a particular field and the file generates, but after generation i see that the values that are supposed to be unique are actually the same i get

id_0
id_0
...
id_0
id_0


when what I really want is
id_0
id_1
...
id_n-1
id_n
any suggestions?



Response

Hi,

This is a by design behavior. Currently there is no options of the 'generate instance' function. You may search some third-party XSD instance generatation tools on the internet.Thanks.

Best regards,
WenJun Zhang
Microsoft Online Partner Support



Also true to form, I never want to use somebody else's code for very simple matters. I much prefer to do it myself (perhaps silly). Enclosed below is the method for the winform that I wrote to generate the instance (names of the schema elements have been changed to protect the innocent)


Dim fs As IO.FileStream = New IO.FileStream("c:\temp\Instance.xml", IO.FileMode.Create)
Dim sw As New IO.StreamWriter(fs)

Dim int As Integer = CInt(TextBox1.Text) 'Hardcode this or provide a textbox
sw.Write("<root>")
Dim i As Integer
For i = 0 To int - 1
sw.Write("<item>")
sw.Write("id_" & i) 'this is really the part that handles unique values
sw.Write("</item>
")
sw.Flush()
fs.Flush()
Next
sw.Write("</root>
")
sw.Close()
fs.Close()

If you're a BizTalk developer, you probably know enough to do this in your sleep. So maybe I all I have saved you is the legwork of trying to do it through the IDE.

I can think of many ways of making this code better, perhaps adding it into the VS.net extensibility model so that it can be invoked from the IDE and could accept any arbitrary schema. Perhaps some smarty pants (obviously with more time than I) could find a way to tie this behaviour into the "Generate instance" button so it would always increment the values over subsequent xml records.

I think that would make a very nice SDK competition entry (though not likely a winner in my opinion)

If any of you have some more elegant ways, or have implemented any of the features listed above (or not listed above) please let me know.

posted on Tuesday, June 07, 2005 5:38 PM

Feedback

# re: Richer Instance Generation 6/7/2005 5:49 PM nsthompson
BTW if you simply want to create an instance file with n records, you can just set the MinOccurs value on that element to "n". The generate instance functionality will handle that no problem, the code above is only for generating UNIQUE values over those rows...or perhaps could be expanded to enforce business rules within that instance

# re: Richer Instance Generation 6/11/2005 8:41 AM Mark Berry
How about gernerate intstance with a minOccurs and then map it. Use a concat and the iteration value.

# re: Richer Instance Generation 6/13/2005 9:07 AM nsthompson
I thought about trying something similar to that, but some of the instances are really big and the mapper on our dev BizTalk server did not perform well with instances over 500,000 records. The WinForms app seemed to be able generate much larger documents in a more timely manner.

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: