elizabethmboyd
New Member
i am trying to read an xml string and then modify it by inserting another xml string, i dont know how to do this, i was struggling since i am a beginner in this area. i search the net and i was really confussing between xmlWriter and xmlReader cuz i dont want to use xmlDocument i found this from microsoft http://msdn.microsoft.com/en-us/library/cc189056(v=vs.95).aspxso my code is like this\[code\] String Mainxmltext = "<ClosedKPICalls>" + "<ServiceInfo> <ServiceNo>HR011</ServiceNo> <ServiceName>Petty cash</ServiceName> "+ "<RecCount>0</RecCount> <RegdKPI>2</RegdKPI> </ServiceInfo> </ClosedKPICalls>"; String xmlinnerText = "<TaskDetails> <name>Jhone</name> <Description>just for testing</Description> </TaskDetails>"; StringBuilder output = new StringBuilder(); using (XmlReader reader = XmlReader.Create(new StringReader(Mainxmltext))) { XmlWriterSettings ws = new XmlWriterSettings(); ws.Indent = true; using (XmlWriter writer = XmlWriter.Create(output, ws)) { // Parse the file and display each of the nodes. while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: writer.WriteStartElement(reader.Name); break; case XmlNodeType.Text: writer.WriteString(reader.Value); break; case XmlNodeType.XmlDeclaration: case XmlNodeType.ProcessingInstruction: writer.WriteProcessingInstruction(reader.Name, reader.Value); break; case XmlNodeType.Comment: writer.WriteComment(reader.Value); break; case XmlNodeType.EndElement: writer.WriteFullEndElement(); break; } } } } MessageBox.Show(output.ToString());}\[/code\]so i am successfully read the first string now how can i insert the second test before the closing tag of the main xml i mean before and my xml should look like this\[code\]<ClosedKPICalls><ServiceInfo> <ServiceNo>HR011</ServiceNo> <ServiceName>Petty cash</ServiceName> <RecCount>0</RecCount> <RegdKPI>2</RegdKPI> </ServiceInfo><TaskDetails> <name>Jhone</name> <Description>just for testing</Description> </TaskDetails></ClosedKPICalls>\[/code\]please helpthank you