Sub PopulateRepeatingTable(ByVal DataSource As String, ByVal SourceXPath As String, ByVal SourceFields() As String, _
ByVal DestXPath As String, ByVal DestTable As String, ByVal DestFields() As String, Optional ByVal Nested As String = "")
Dim NodeIterator As XPathNodeIterator = DataSources(DataSource).CreateNavigator().Select(SourceXPath, NamespaceManager)
Dim Field As String
For Each Node As XPathNavigator In NodeIterator
Dim MyNamespace As String = NamespaceManager.LookupNamespace("my")
If Node Is Nothing Then
'Do Nothing
Else
Using Writer As XmlWriter = MainDataSource.CreateNavigator().SelectSingleNode(DestXPath, NamespaceManager).AppendChild()
Writer.WriteStartElement(DestTable, MyNamespace)
Dim i As Integer = 0
For Each Field In SourceFields
If Node.SelectSingleNode(SourceFields(i)) Is Nothing Then
Writer.WriteElementString(DestFields(i), MyNamespace, "")
Else
Writer.WriteElementString(DestFields(i), MyNamespace, Node.SelectSingleNode(SourceFields(i)).ToString)
End If
i = i + 1
Next
Writer.WriteEndElement()
Writer.Close()
End Using
End If
Next
End Sub
Repeater XPath:
"/my:ProgrammeForm/my:Structure/my:CoreStream/my:ElectiveBundlesSectionGroup/my:ElectiveBundlesSection" (Yes, the repeater is called ElectiveBundlesSection. I must rename to something a bit better)
Nested Repeater XPath:
"my:ProgrammeForm/my:Structure/my:CoreStream/my:ElectiveBundlesSectionGroup/my:ElectiveBundlesSection/my:ElectiveBundlesGroup/my:ElectiveBundles"
I keep running in to a NullException... Whichever repeater I populate first, populates successfully e.g. I can call the function to populate the nested repeater but if i call the function again to populate the parent, a Null Exception is encountered. Same thing happens in reverse.
The XmlWriter appears to be creating only certain fields for a node and then when I try to populate either nested fields or parent fields of that node, it can't seem to find them. I don't really understand how it works so here I am! :)
This is a project for work and i need to have it sorted out asap. I'd really appreciate advice on this.
Thanks a million,
Ben