johnsanthosh
January 24th, 2005, 02:30 AM
Hi
I have done a program, such that program reads a xml schema file and it also reads a xml file which has some field names . it stores the field names in an raarray and compares to the schema file, and if any field name in the xml file matches to the xml schema file and writes data's which is in theh directory itself for that particular field alone.
and remaining fields in the xml schema will be automatically loaded with values according to the datatype.
I have done the program, but now my problem is that. the program goes for a loop and creates about 200 values for all the fields. Now if the field name xml file has only 30 records then its writing the 30 records and remaining are automatic values which is given inside teh program for that datatype alone. now what I need is that it should store the first 30 records and remaining should bbe repeated like the same above 30 values.pls help me to do this. i AM PASTING MY PROGRAM ALONG WITH THIS THREAD
private void button2_Click(object sender, System.EventArgs e)
{
string sPath = "C:\\CDEV\\testdatagenerator";
//Input Data xml file where datafiles [eg: billto_name.xml] is available
ArrayList FiledNames = new ArrayList();
XmlDocument xdc = new XmlDocument();
//Read the file which contain the field names
xdc.Load(@"C:\CDEV\testdatagenerator\Field Names.xml");
XmlNodeList nodFields = xdc.DocumentElement.SelectNodes("//item") ;
for(int i=0; i<nodFields.Count;i++)
FiledNames.Add(nodFields.Item(i).InnerXml);
ArrayList MatchList = new ArrayList();
//Read the schema file
dataSet1.ReadXmlSchema(txtSchema.Text);
foreach (DataTable dTbl in dataSet1.Tables)
{
int nColIndex = 0;
foreach (DataColumn dColmn in dTbl.Columns)
{
for (int y=0; y<FiledNames.Count; y++)
{
if(dColmn.ColumnName.ToString() == FiledNames[y].ToString())
{
string sFileName = "", sColumnName = "";
sColumnName = FiledNames[y].ToString();
sFileName = sColumnName + ".xml";
MatchList.Add(new FieldList(nColIndex, FiledNames[y].ToString(), sFileName));
break;
}
}
nColIndex++;
}
}
foreach (DataTable dTbl in dataSet1.Tables)
{
object[] oValues = new object[dTbl.Columns.Count];
String sXPath = "//" + dTbl.TableName.ToString();
for(int i = 0; i <= 200; i++)
{
int k=0;
foreach (DataColumn dColmn in dTbl.Columns)
{
bool bFound = false;
foreach(FieldList FL in MatchList)
{
if(dColmn.ColumnName.ToString() == FL.ColDesc.ToString())
{
//Load the data file
if(File.Exists(sPath + "\\" + FL.FileName.ToString()))
{
xdc.Load(sPath + "\\" + FL.FileName.ToString());
String xPath = "//" + FL.ColDesc.ToString();
XmlNode node;
node = xdc.SelectNodes(xPath).Item(i);
if(node != null)
{
oValues[k] = node.InnerText;
bFound = true;
break;
}
}
}
}
if(!bFound)
{
switch(dColmn.DataType.ToString())
{
case "System.String":
oValues[k] = (string) "castle Hampers" + i;
break;
case "System.Int32":
oValues[k] = (int) 66 + i;
break;
case "System.DateTime":
oValues[k] = new DateTime(2004,01,30).AddDays(i * 1);
break;
case "System.Decimal":
oValues[k] = new Decimal(1900.20) + i;
break;
case "System.Int16":
oValues[k] = (short) 3256 + i;
break;
case "System.Int64":
oValues[k] = (long) 400 + i;
break;
case "System.Double":
oValues[k] = (double) 8888 - i;
break;
case "System.Single":
oValues[k] = (float) 4.5 + i;
break;
}
}
k++;
}
dTbl.Rows.Add(oValues);
}
}
}
JOHN SANTHOSH
I have done a program, such that program reads a xml schema file and it also reads a xml file which has some field names . it stores the field names in an raarray and compares to the schema file, and if any field name in the xml file matches to the xml schema file and writes data's which is in theh directory itself for that particular field alone.
and remaining fields in the xml schema will be automatically loaded with values according to the datatype.
I have done the program, but now my problem is that. the program goes for a loop and creates about 200 values for all the fields. Now if the field name xml file has only 30 records then its writing the 30 records and remaining are automatic values which is given inside teh program for that datatype alone. now what I need is that it should store the first 30 records and remaining should bbe repeated like the same above 30 values.pls help me to do this. i AM PASTING MY PROGRAM ALONG WITH THIS THREAD
private void button2_Click(object sender, System.EventArgs e)
{
string sPath = "C:\\CDEV\\testdatagenerator";
//Input Data xml file where datafiles [eg: billto_name.xml] is available
ArrayList FiledNames = new ArrayList();
XmlDocument xdc = new XmlDocument();
//Read the file which contain the field names
xdc.Load(@"C:\CDEV\testdatagenerator\Field Names.xml");
XmlNodeList nodFields = xdc.DocumentElement.SelectNodes("//item") ;
for(int i=0; i<nodFields.Count;i++)
FiledNames.Add(nodFields.Item(i).InnerXml);
ArrayList MatchList = new ArrayList();
//Read the schema file
dataSet1.ReadXmlSchema(txtSchema.Text);
foreach (DataTable dTbl in dataSet1.Tables)
{
int nColIndex = 0;
foreach (DataColumn dColmn in dTbl.Columns)
{
for (int y=0; y<FiledNames.Count; y++)
{
if(dColmn.ColumnName.ToString() == FiledNames[y].ToString())
{
string sFileName = "", sColumnName = "";
sColumnName = FiledNames[y].ToString();
sFileName = sColumnName + ".xml";
MatchList.Add(new FieldList(nColIndex, FiledNames[y].ToString(), sFileName));
break;
}
}
nColIndex++;
}
}
foreach (DataTable dTbl in dataSet1.Tables)
{
object[] oValues = new object[dTbl.Columns.Count];
String sXPath = "//" + dTbl.TableName.ToString();
for(int i = 0; i <= 200; i++)
{
int k=0;
foreach (DataColumn dColmn in dTbl.Columns)
{
bool bFound = false;
foreach(FieldList FL in MatchList)
{
if(dColmn.ColumnName.ToString() == FL.ColDesc.ToString())
{
//Load the data file
if(File.Exists(sPath + "\\" + FL.FileName.ToString()))
{
xdc.Load(sPath + "\\" + FL.FileName.ToString());
String xPath = "//" + FL.ColDesc.ToString();
XmlNode node;
node = xdc.SelectNodes(xPath).Item(i);
if(node != null)
{
oValues[k] = node.InnerText;
bFound = true;
break;
}
}
}
}
if(!bFound)
{
switch(dColmn.DataType.ToString())
{
case "System.String":
oValues[k] = (string) "castle Hampers" + i;
break;
case "System.Int32":
oValues[k] = (int) 66 + i;
break;
case "System.DateTime":
oValues[k] = new DateTime(2004,01,30).AddDays(i * 1);
break;
case "System.Decimal":
oValues[k] = new Decimal(1900.20) + i;
break;
case "System.Int16":
oValues[k] = (short) 3256 + i;
break;
case "System.Int64":
oValues[k] = (long) 400 + i;
break;
case "System.Double":
oValues[k] = (double) 8888 - i;
break;
case "System.Single":
oValues[k] = (float) 4.5 + i;
break;
}
}
k++;
}
dTbl.Rows.Add(oValues);
}
}
}
JOHN SANTHOSH