bwg 7/29/2008 11:27:27 AM

Adding Multiple Customers

Hi all,

 I am new to econnect, and what I'm trying to do is take an xml file, loop through it, and add its customers to an econnect xml doc.

 I started by using their examples as a template, and trying to do all of this in the Serialization sub.  However as a result of this code, I get a econnect XML file, but its the final source record repeated the same number of times the loop ran (450 source records = 450 repeats of the final record).

 Any help would be appreciated, as I'm sure this is a fairly common thing to do.  Even pointing me in the direction of more documentation would be greatly appreciated.

 Regards,

-bg

 

Public Shared Sub SerializeCustomerObject(ByVal filename As String)

Dim serializer As New XmlSerializer(GetType(eConnectType))

Dim eConnect As New eConnectType

Dim customer As New taUpdateCreateCustomerRcd

Dim customertype As New RMCustomerMasterType

Dim i As Integer

Dim textDoc As StreamWriter

Dim doc As XmlDocument

Dim nodes As XmlNodeList Dim elem As XmlElement

'Create logfile

textDoc = New StreamWriter("C:\GPlogfile.txt")

i = 0

 

'Populate the taUpdateCreateCustomerRcd XML node with customer data

Try

' Create a new XmlDocument

doc = New XmlDocument()

' Load data

doc.Load("C:\eConnect\Projects\VB DOT NET Console Application\bin\CustomerRaw.xml")

elem = doc.DocumentElement

nodes = doc.DocumentElement.ChildNodes

 

 

For Each elem In nodes

 

 

With customer

 

.CUSTNMBR = elem(
"CUSTNMBR").InnerText

.CUSTNAME = elem("CUSTNAME").InnerText

.ADDRESS1 = elem("ADDRESS1").InnerText

.ADRSCODE = elem("ADRSCODE").InnerText

.CITY = elem("CITY").InnerText

.ZIPCODE = elem("ZIPCODE").InnerText

textDoc.WriteLine("id =" & i & " customer = " & customer.CUSTNAME)

 

End With

 

'Populate the RMCustomerMasterType schema with the taUpdateCreateCustomerRcd XML node object

customertype.taUpdateCreateCustomerRcd = customer

'Populate the eConnect XML document object with the RMCustomerMasterType schema object

ReDim Preserve eConnect.RMCustomerMasterType(i)

eConnect.RMCustomerMasterType(i) = customertype

 

'increase index

i = i + 1

 

Next

'Create file and XML writer objects to serialize the eConnect XML document

Dim fs As New FileStream(filename, FileMode.Create) Dim writer As New XmlTextWriter(fs, New UTF8Encoding)

' Use the XmlTextWriter to serialize the eConnect XML document object to the file

serializer.Serialize(writer, eConnect)

writer.Close()

 

Catch ex As System.ApplicationExceptionConsole.Write("Error occurred while creating customer XML document and file")

Console.Write(ex.ToString)

End Try

textDoc.Close()

End Sub

 

 

Version: Unknown or N/A
Section: eConnect


Table Definition Quick Links
All Tables
SOP Tables
RM Tables
GL Tables
POP Tables
HR Tables
PM Tables
UPR Tables
IV Tables
Olympic Tables
3