我添加了以下元素
<PriorCourtFileNumber>
<CaseNumber>555</CaseNumber>
</PriorCourtFileNumber>
进入文档对象(aobjXMLInputDoc)但它被添加到此aobjXMLInputDoc的底部。
我想将它移到元素<Integration>
我该怎么做?
这是aobjXMLInputDoc对象的样子
<Pipeline>
<SourceXML>
<Integration>
<Case>
<CaseNumber/>
</Case>
<IntegrationConditions>
<IntegrationCondition>
<NotificationEvent/>
</IntegrationCondition>
</IntegrationConditions>
<PriorCourtFileNumber>
<CaseNumber>555</CaseNumber>
</PriorCourtFileNumber>
</Integration>
</SourceXML>
这就是我想要的样子
<Pipeline>
<SourceXML>
<Integration>
<PriorCourtFileNumber>
<CaseNumber>555</CaseNumber>
</PriorCourtFileNumber>
<Case>
<CaseNumber/>
</Case>
<IntegrationConditions>
<IntegrationCondition>
<NotificationEvent/>
</IntegrationCondition>
</IntegrationConditions>
</Integration>
</SourceXML>
以下是我的vb.net代码,其中添加了元素<PriorCourtFileNumber>
及其子<CaseNumber>
objXMLElement = aobjXMLInputDoc.CreateElement("PriorCourtFileNumber")
aobjXMLInputDoc.DocumentElement.SelectSingleNode("SourceXML/Integration").AppendChild(objXMLElement)
objXMLElement = aobjXMLInputDoc.CreateElement("CaseNumber")
objXMLElement.InnerText = strPriorCaseNumber
aobjXMLInputDoc.DocumentElement.SelectSingleNode("SourceXML/Integration/PriorCourtFileNumber").AppendChild(objXMLElement)
答案 0 :(得分:0)
只需使用XmlNode
这样的InsertBefore方法:
Dim integrationNode =aobjXMLInputDoc.
DocumentElement.
SelectSingleNode("SourceXML/Integration")
integrationNode.InsertBefore(objXMLElement, integrationNode.FirstChild)