Coloco el code.
Código:
La parte dos es la que quiero anadir manualmente es decir meter los datos tecleando, ya que ahi es de forma automatica.Imports System.Xml Imports System.Text Module Module1 Public Sub Main() Try ' Create an Xml document instance and load XML data. Dim doc As XmlDocument = New XmlDocument() doc.Load("C:\CFDTest\Archivos\DEMO.xml") 'I. Modificación '1. Incrementar los valores de los atributos libro Id por 100. Dim nodeList As XmlNodeList = doc.SelectNodes("//Book") Dim node As XmlNode For Each node In nodeList node.Attributes("Id").Value = node.Attributes("Id").Value + 100 Next '2. Actualización de la capitalización de los títulos de los libros. For Each node In nodeList node.FirstChild.InnerText = (node.FirstChild.InnerText).ToUpper Next '3. Modifique la instrucción de declaración de XML para tener codificación Unicode. Dim decl As XmlDeclaration = doc.FirstChild decl.Encoding = "UTF-16" 'II. adición '1. Crear un elemento nuevo libro. ' Dim newElem As XmlElement = doc.CreateElement("Book") 'Agregar el atributo id. 'Dim newAttr As XmlAttribute = doc.CreateAttribute("Id") 'newAttr.Value = "103" 'newElem.Attributes.Append(newAttr) ' Create the child nodes. The following example shows various ways to add child nodes. 'newElem.InnerXml = "<Title></Title><Author></Author>" 'Dim txtNode As XmlText = doc.CreateTextNode("A BRIEF HISTORY OF TIME") 'newElem.FirstChild.AppendChild(txtNode) 'newElem.AppendChild(doc.CreateWhitespace(ControlChars.CrLf)) 'newElem.Item("Author").InnerText = "Stephen Hawking" '2. Agregue el nuevo elemento al final de la lista de libros. 'doc.DocumentElement.AppendChild(newElem) 'III. supresión '1. Elimine los nodos de elementos Género Book. For Each node In nodeList node.RemoveChild(node.SelectSingleNode("Genre")) Next 'Muestra el resultado en la ventana de depuración. Diagnostics.Debug.Write("{0}", doc.OuterXml & vbNewLine) '2. Guarde la modificación XML en un archivo en formato Unicode. doc.PreserveWhitespace = True Dim wrtr As XmlTextWriter = New XmlTextWriter("C:\CFDTest\Archivos\DEMO_Out.xml", Encoding.Unicode) doc.WriteTo(wrtr) wrtr.Close() Console.WriteLine(" C:\CFDTest\Archivos\DEMO_Out.xml Se ha creado correctamente") 'Console.ReadLine() Console.WriteLine("") Console.WriteLine("") Console.WriteLine("") Console.WriteLine("") Console.WriteLine("") Console.WriteLine("") Console.WriteLine(" Presione la tecla ENTER para terminar el programa... ") Console.ReadLine() Catch xmlex As XmlException ' Handle the Xml Exceptions here. Console.WriteLine("{0}", xmlex.Message) Catch ex As Exception ' Handle the generic Exceptions here. Console.WriteLine("{0}", ex.Message) End Try End Sub End Module
COmo podria hacer eso.
Saludos...
