Preface: This is my first interaction with .Net and XML data manipulation.
I need help with cloning all the children form a specific node (<MonitoringData>
) and all of it's children. There are 15 instances of the node <MonitoringData>
that will need to be cloned. Eventually I will need to insert data from an access DB into a few of the children of <MonitoringData>
but I'll figure that out once I get there.
XML Document looks as follows:
<MetaData>
<MonitoringData type="Sample">
.....few other children
<IndividualMonitoringResult>
<IndividualResult>
<MonitoringStartDate>2019-04-01</MonitoringStartDate>
<MeasurementQualifier/>
<MeasurementValue/>
<LimitOfDetection/>
<LimitOfQuantification/>
<MeasurementUnit>mg/L</MeasurementUnit>
<LaboratoryCertificationNo/>
<QCExceedance/>
<OrganicsAnalyzedDate/>
</IndividualResult>
</IndividualMonitoringResult>
</MonitoringData>
<MonitoringStartDate>2019-04-02</MonitoringStartDate>
<MeasurementQualifier/>
<MeasurementValue/>
<LimitOfDetection/>
<LimitOfQuantification/>
<MeasurementUnit>mg/L</MeasurementUnit>
<LaboratoryCertificationNo/>
<QCExceedance/>
<OrganicsAnalyzedDate/>
</IndividualResult>
</IndividualMonitoringResult>
<IndividualResult>
<IndividualMonitoringResult>
...Duplication for each day of month
</IndividualResult>
</IndividualMonitoringResult>
<MonitoringData>
....Duplication of last MonitoringData
</MonitoringData>
</MetaData>
This is the code I currently have. The exception I receive is 'Expression must evaluate to a node-set'
Dim xdc As New XmlDocument
xdc.Load(GlobalVariables.strXMLFileName)
Dim strXPATH As String = "/u:eDMR/u:Submission/u:Facility/u:Report/u:MonitoringLocationGroup/u:MonitoringData/"
Dim nsmgr As New XmlNamespaceManager(xdc.NameTable)
nsmgr.AddNamespace("u", xdc.DocumentElement.NamespaceURI)
Dim xnl As XmlNodeList = xdc.DocumentElement.SelectNodes(strXPATH, nsmgr)
For Each xnd As XmlNode In xnl
xnd.CloneNode(True)
Next
I understand that the code I've presented is intended to locate a single child of a parent and then clone it. I cannot for the life of me figure out how to grab the whole node. I found a solution but it's in C#. How to make a copy of a XML node with all their child nodes and values but different name C# .NET
Expected result would be to grab all of the children of node <MonitoringData>
in memory to which I will then insert data into a few of the children. I'll figure data insertion out on my own. I would like help figuring out how to grab all of the children of a particular node.