CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2005
    Posts
    73

    repeat the values

    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

  2. #2
    Join Date
    Oct 2004
    Location
    South Africa
    Posts
    86

    Re: repeat the values

    hi
    "the program goes for a loop and creates about 200 values for all the fields"

    if this is your problem, its because you have specified it to do so via the following code

    for(int i = 0; i <= 200; i++)
    {
    int k=0;
    foreach
    }

  3. #3
    Join Date
    Jan 2005
    Posts
    73

    Re: repeat the values

    Hi

    Thank you for ur response.

    What I need is that

    For ex:

    Consider let the program reads a xml schem file with fields "Name"(string), "Salary"(decimal) and "address"(string)

    Now I have some values for the field Name alone in a a xml file( about 5 values)

    Now I have to create a new xml file for the schema with about 10 data's for each fields.

    so when the program reads the schema it automatically writes data for the fields
    salary and address according to the datatype ( as
    jj nagar1, jjnagar2.... upto 10 for "address" and 8800.10, 8900.10, .... so on for "salary")
    And for the field "Name" It should read values from a different xml file?( ie the file which has 5 values for the field Name in seperate xml file)

    I have did this all
    but what I need is that as i want to create 10 values, in the " Name" field after the 5 values are inserted , the remaining 5 values should be same as the previous 5 data's , it should be repeated.
    whereas now in my program, the frst five values are from the xml file and the remaing are jjnagar6. jjnagar7..etcc like that . (which i have specified in the program for the string datatype)

    can u please help me to change that according to the requirement.

    santhosh

  4. #4
    Join Date
    Nov 2004
    Location
    Poland
    Posts
    1,355

    Re: repeat the values

    I have did this all
    I think that it is somhow collective work of codegurus . U have posted many threads (some of them under different name) on the same problem (changing subject of post only).

    Are U testing if program can be written all by CG ?

  5. #5
    Join Date
    Nov 2004
    Location
    Poland
    Posts
    1,355

    Re: repeat the values


  6. #6
    Join Date
    Jan 2005
    Posts
    73

    Re: repeat the values

    No


    while posting new thread I tried to delete my previous thread. But I couldnt.
    and also even though its the same program, I have made several changes and completed almost except a minor change to do.

    How to delete my previous threads.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured