Wrox Programmer Forums
|
BOOK: Wrox's Visual Basic 2005 Express Edition Starter Kit ISBN: 978-0-7645-9573-8
This is the forum to discuss the Wrox book Wrox's Visual Basic 2005 Express Edition Starter Kit by Andrew Parsons; ISBN: 9780764595738
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Wrox's Visual Basic 2005 Express Edition Starter Kit ISBN: 978-0-7645-9573-8 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 28th, 2011, 05:31 AM
Registered User
 
Join Date: Jun 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Writing multiple files in one xml file

Hi guys

I am new in the programming field and I am trying to write code to display an xml file with 3 records under it, but this code writes 3 separate xml files each with one record, can anyone please help.

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Xml;


namespace MCTest1
{
[TestClass]
public class UnitTest1
{

static int i = 0;
private TestContext testContextInstance;
public TestContext TestContext
{
get { return testContextInstance; }
set { testContextInstance = value; }
}


[DataSource("Microsoft.VisualStudio.TestTools.DataS ource.CSV", "|DataDirectory|\\Details.csv", "Details#csv", DataAccessMethod.Sequential), DeploymentItem("MCTest1\\Details.csv"), TestMethod]
public void Generatefiles()
{

System.Xml.XmlDocument xdoc = new System.Xml.XmlDocument();

string xml = "";
int counter = 3;

while (counter <= 3)
{
xml = "<PERSONALDETAILS>" +
"<SURNAME>" + testContextInstance.DataRow["SURNAME"] + "</SURNAME>" +
"<SURNAME>" + testContextInstance.DataRow["SURNAME"] + "</SURNAME>" +
"<SURNAME>" + testContextInstance.DataRow["SURNAME"] + "</SURNAME>" +
"</PERSONALDETAILS>";

counter = counter + 1;
}


string header = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
"<ns0:TransactionRequest xmlns:ns0=\"http://ABSA.DTM.NMB\">" +
"<DETAILS>";
string footer = "</DETAILS>" +
"</ns0:TransactionRequest>";

xdoc.LoadXml(header + xml + footer);


xdoc.Save(@"C:\logs\NMBMULTI" + DateTime.Now.ToString(i.ToString() + "yyyyMMdd" + testContextInstance.DataRow["SURNAME"]) + ".XML");
i++;



}
}
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
writing into xml file jerryjohn XML 1 August 18th, 2006 02:40 AM
grouping multiple xml files in one file bcogney XSLT 3 April 21st, 2006 03:58 AM
writing to am xml file MOU Classic ASP XML 0 July 6th, 2005 07:38 AM
Reading from a xml file and writing to another billy_bob_the_3rd XML 5 April 29th, 2005 01:40 PM
Writing XML file within Loop (c#) rathbird General .NET 0 December 13th, 2004 05:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.