I thought that I would post my solution thus far.
The main problem I had was that my terminology was incorrect, I was referring to nested nodes not inner nodes.
I have added the code which I used to produce the nested nodes at the end of this post in case anyone else is interested.
The only problem I have now is that the XML isn't exactly how I would have liked, the current XML looks like this...
Code:
<Client>
<ClientID>12345</ClientID>
...
<Companies>
<LinkClientID>12345</LinkClientID>
<CompanyID>36007</CompanyID>
</Companies>
<Companies>
<LinkClientID>12345</LinkClientID>
<CompanyID>36019</CompanyID>
</Companies>
</Client>
Where as I would prefer it to look like this
Code:
<Client>
<ClientID>12345</ClientID>
...
<Companies>
<Company>
<CompanyID>36007</CompanyID>
</Company>
<Company>
<CompanyID>36007</CompanyID>
</Company>
</Companies>
</Client>
The LinkClientID is the FK in the Company table, so I would rather not show it as its just taking up space as its already known above.
Also I would have preferred each company to be in its own tag, rather than being in its own Companies tag.
Anyone have any idea's on how to solve this?
Code:
Private Function produceXML(ByVal xmlQry As String, ByVal outLocation As String, ByVal dataSetName As String) As String
'Information about Nested node from...
'http://dotnetslackers.com/articles/ado_net/MappingDataSetToXMLAndBackwards.aspx
Dim conn As New OleDb.OleDbConnection(connectionString)
Dim ds As New DataSet
Dim da As New OleDb.OleDbDataAdapter(xmlQry, conn)
Dim pk As DataColumn
Dim fk As DataColumn
Dim rl As DataRelation
Dim blExists As Boolean = True
Dim outFile As String = ""
da.Fill(ds, "Clients")
xmlQry = "SELECT tblDirectorDetails.LinkClientID,tblClient.ClientID As CompanyID FROM tblDirectorDetails INNER JOIN tblClient ON tblDirectorDetails.CompanyClientID=tblClient.ClientID WHERE tblDirectorDetails.LinkClientID IN (SELECT ClientID FROM tblClient WHERE ClientType=1) AND tblDirectorDetails.CompanyClientID IN (SELECT ClientID FROM tblClient WHERE ClientType=2)"
da.SelectCommand = New OleDb.OleDbCommand(xmlQry, conn)
da.Fill(ds, "Companies")
conn.Close()
pk = ds.Tables("Clients").Columns("ClientID")
fk = ds.Tables("Companies").Columns("LinkClientID")
rl = ds.Relations.Add(pk, fk)
rl.Nested = True
ds.DataSetName = dataSetName
If Not outLocation.EndsWith("\") Then
outLocation &= "\"
End If
While blExists
outFile = outLocation & DateTime.Now.Ticks & ".xml"
blExists = FileExists(outFile)
End While
'ds.WriteXmlSchema("C:\out.xsd")
ds.WriteXml(outFile, XmlWriteMode.IgnoreSchema)
Return outFile
End Function