Declaring New Array of Type Using VB Causes XML Error

Using Endicia's Label Server, I have declared a variable of type  'CustomsItem' as follows:

 Dim CustomsItem(9) As ewsLabelService.CustomsItem
                If txtCustomsQty1.Text <> "" Then
                    CustomsItem(0) = New ewsLabelService.CustomsItem()
                    CustomsItem(0).Description = txtCustomsDescription1.Text
                    CustomsItem(0).Quantity = txtCustomsQty1.Text
                    CustomsItem(0).Weight = txtCustomsWeight1.Text
                    CustomsItem(0).HSTariffNumber = txtCustomsTariffNum1.Text
                    CustomsItem(0).Value = txtCustomsValue1.Text
                    CustomsItem(0).CountryOfOrigin = Get2LetterCountryCode(cmbCustomsCountry1.Text)

                End If

This code executes just fine.  However, the xml it sends to Endicia contains the following snippet:

        <HSTariffNumber />
      <CustomsItem xsi:nil="true" />

The next to the last line is the problem and I have concluded that it is caused by not declaring the array as new all on one line.  Is there a way to declare the array as a new array of type customsitem on a single line or do you know of another way I can do the declaration without 'damaging' my xml?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jessica WhitleySoftware DeveloperCommented:
It appears that you are asking for a custom items number and calling it a text. When referencing the item are you converting your number to a string?
ProgrammingIsFunAuthor Commented:
That is not the issue here.  CustomsItem is a type referenced from a service provided Endicia. This line of code:

CustomsItem(0) = New ewsLabelService.CustomsItem()

Adds this line into the XML Output:

 <CustomsItem xsi:nil="true" />

this is a bad thing...I need to declare the array on one line to prevent this (I Hope).  something like this:

Dim CustomsItem(9) As ewsLabelService.CustomsItem = New ewslabelservice.Customsitem{}

But I cannot figure out the syntax.
Jacques Bourgeois (James Burger)PresidentCommented:
xsi:nil="true" means that an element should not contain content (

Is it possible that you do not have all the 10 entries in your array? In such a case, it is possible that the method that you use to generate the XML add that "extra" line. Maybe trimming your array with a Redim Preserve before generating the XML will do the trick.

What do you use to generate the XML. Some methods have parameters that let you control the way the XML is generated.

In last resort, you could write the code that creates the XML yourself. It would be quite easy for such simple XML.
Jacques Bourgeois (James Burger)PresidentCommented:
You have the syntax in reverse for your "declaration" on one line. The index should be specified in the constructor, not on the Dim.

Dim CustomsItem() As ewsLabelService.CustomsItem = New ewslabelservice.Customsitem(9){}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.