Erstellen von XML-Knoten

Ich habe die folgende XML-Datei, wo ich will hinzufügen, ein neues Kind unter den ersten <Profile_Path></Profile_Path> Knoten.

Ursprünglichen XML:

<?xml version="1.0" encoding="utf-8"?>
<Profiles>
  <Profile>
    <Profile_Name>Profile 1</Profile_Name>
    <Profile_Path>E:\Test</Profile_Path>
  </Profile>
  <Profile>
    <Profile_Name>Profile 2</Profile_Name>
    <Profile_Path>E:\Test</Profile_Path>
  </Profile>
</Profiles>

Nach ausführen des Codes...

Public Sub CreateProjectXml()

    ProfileList.Load(xml_path)
    Dim profilesNode As XmlNode = ProfileList.SelectSingleNode("Profiles")
    Dim profiles As XmlNodeList = profilesNode.SelectNodes("Profile")
    Dim profile As XmlNode = profiles(2)

    Dim project_info As XmlElement = ProfileList.CreateElement("Project_Name")

    project_info.InnerText = "Project 1"
    ProfileList.DocumentElement.AppendChild(project_info)

    ProfileList.Save(xml_path)

End Sub

Ich Folgendes Resultat erhalten:

    <?xml version="1.0" encoding="utf-8"?>
    <Profiles>
      <Profile>
        <Profile_Name>Profile 1</Profile_Name>
        <Profile_Path>E:\Test</Profile_Path>
      </Profile>
      <Profile>
        <Profile_Name>Profile 2</Profile_Name>
        <Profile_Path>E:\Test</Profile_Path>
      </Profile>
      <Project_Name>Project 1</Project_Name>
    </Profiles>

Mir bitte helfen mit dem richtigen code!

Es wäre hilfreich, wenn Sie gab auch ein Beispiel von der gewünschten XML-Ausgabe. Es ist nicht ganz klar, was Sie versuchen zu erreichen.

InformationsquelleAutor guest | 2013-10-04

Schreibe einen Kommentar