如何将PriorCourtFileNumber元素从输入文档的底部移到顶部?

时间:2016-02-12 17:42:56

标签: xml vb.net

我添加了以下元素

<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)

1 个答案:

答案 0 :(得分:0)

只需使用XmlNode这样的InsertBefore方法:

Dim integrationNode =aobjXMLInputDoc.
     DocumentElement.
     SelectSingleNode("SourceXML/Integration")

integrationNode.InsertBefore(objXMLElement, integrationNode.FirstChild)