Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET 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 December 31st, 2004, 06:40 AM
Authorized User
 
Join Date: Dec 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default Hi IMAR, clear question

Hi

Thank you for your response.

At present The program what it does is reads any xml schem afile and load data's automatically for each fields in a new xml file. (ie, fora field name "company name" datatype-string - ( values stored as john1, john2..etc up to 200)like that.

Now what I need is , to give a meaning full data.
Ie, I have another xml file with same field name " company name" with meaninful data'a upto 200 data's.

Now I want to insert the data's from that xml file( that field "company name" alone) into the new xml field (comapny name").
Transferring a single field data's into a new xml file .

PLEASE HELP ME TO DO THAT.


dhol


__________________
SureShot
 
Old December 31st, 2004, 07:21 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You can use various classes and method in the System.Xml namespace for this. For example, the XPathNavigator allows you to browse through the data "using a cursor model".

But you could also create an XmlDocument object and read from that. Basically, it all depends on your business requirements and your current knowledge about XML in .NET, both of which still aren't clear to me. If I were you, I'd try to break down this app, and try to write down the actions you need to perform. If you write down the functionality of an app like this, it becomes clearer what you want it to do, which helps in a) building the app in the first place, b) knowing where to search for more help and c) communicating the problem to others, including people on this forum.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Cinderella's big score by Sonic Youth (Track 4 from the album: Dirty boots) What's This?
 
Old December 31st, 2004, 11:48 PM
Authorized User
 
Join Date: Dec 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

I wish everyone a Happy New year .

Then coming back to my problem. Pls can you give me the proper topics to searcg thru the net to rectify this problem.

As I am ne w to dot net, I dont know the kewords to serach.
Pls help me to do that.

dhol


 
Old January 1st, 2005, 12:37 AM
Authorized User
 
Join Date: Dec 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

I wish you a Joyful and Happy New Year.

I am new to c# , so I dont know how to do.

ie,
My requirement exactly is :

Now My program reads a schema file( with field names name(string), salary(decimal)).
They are read and the values are inserted to the fields automatically.Like
(john1,john2,john3,..etc. for name)(2000, 2001,2002 , ..etc for salary).They are written into a xml file(say for instance salaryemp.xml).
this is what happens to my program.

Now what I have to do , I should be able to read another xml file( say for instance corporate.xml) which also has this name field with many original datas( like james, george, munna,..etc. ). So my program should read these values and fed(insert) into salary.xml file(only the name field should get altered with the values of corporate.xml). the salary field should remain the same.

pls help me to do that .
Just give me a coding help.
Here I am submitting my coding.
pls help me

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Xml;
using System.Xml.Schema;

namespace testdatagenerator
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        private System.Windows.Forms.TextBox txtSchema;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.TextBox txtXml;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Button button3;
        private System.Windows.Forms.DataGrid dataGrid1;
        private System.Data.DataSet dataSet1;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.txtSchema = new System.Windows.Forms.TextBox();
            this.button1 = new System.Windows.Forms.Button();
            this.txtXml = new System.Windows.Forms.TextBox();
            this.button2 = new System.Windows.Forms.Button();
            this.button3 = new System.Windows.Forms.Button();
            this.dataGrid1 = new System.Windows.Forms.DataGrid();
            this.dataSet1 = new System.Data.DataSet();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            ((System.ComponentModel.ISupportInitialize)(this.d ataGrid1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.d ataSet1)).BeginInit();
            this.SuspendLayout();
            //
            // txtSchema
            //
            this.txtSchema.Location = new System.Drawing.Point(232, 24);
            this.txtSchema.Name = "txtSchema";
            this.txtSchema.Size = new System.Drawing.Size(368, 20);
            this.txtSchema.TabIndex = 0;
            this.txtSchema.Text = "";
            //
            // button1
            //
            this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            this.button1.Location = new System.Drawing.Point(616, 24);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(64, 23);
            this.button1.TabIndex = 1;
            this.button1.Text = "Browse";
            this.button1.Click += new System.EventHandler(this.button1_Click);
            //
            // txtXml
            //
            this.txtXml.Location = new System.Drawing.Point(232, 64);
            this.txtXml.Name = "txtXml";
            this.txtXml.Size = new System.Drawing.Size(368, 20);
            this.txtXml.TabIndex = 2;
            this.txtXml.Text = "";
            //
            // button2
            //
            this.button2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            this.button2.Location = new System.Drawing.Point(616, 64);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(64, 23);
            this.button2.TabIndex = 3;
            this.button2.Text = "Load";
            this.button2.Click += new System.EventHandler(this.button2_Click);
            //
            // button3
            //
            this.button3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            this.button3.Location = new System.Drawing.Point(696, 64);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(64, 23);
            this.button3.TabIndex = 4;
            this.button3.Text = "Save";
            this.button3.Click += new System.EventHandler(this.button3_Click);
            //
            // dataGrid1
            //
            this.dataGrid1.DataMember = "";
            this.dataGrid1.DataSource = this.dataSet1;
            this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
            this.dataGrid1.Location = new System.Drawing.Point(0, 120);
            this.dataGrid1.Name = "dataGrid1";
            this.dataGrid1.Size = new System.Drawing.Size(776, 320);
            this.dataGrid1.TabIndex = 5;
            //
            // dataSet1
            //
            this.dataSet1.DataSetName = "NewDataSet";
            this.dataSet1.Locale = new System.Globalization.CultureInfo("en-US");
            //
            // label1
            //
            this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            this.label1.Location = new System.Drawing.Point(32, 24);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(184, 23);
            this.label1.TabIndex = 6;
            this.label1.Text = "Enter the Xml Schema";
            //
            // label2
            //
            this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            this.label2.Location = new System.Drawing.Point(32, 64);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(192, 23);
            this.label2.TabIndex = 7;
            this.label2.Text = "Enter the Xml file";
            //
            // Form1
            //
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(808, 454);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.dataGrid1);
            this.Controls.Add(this.button3);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.txtXml);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.txtSchema);
            this.Name = "Form1";
            this.Text = "TestDatagenerator";
            ((System.ComponentModel.ISupportInitialize)(this.d ataGrid1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.d ataSet1)).EndInit();
            this.ResumeLayout(false);

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.Run(new Form1());
        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            OpenFileDialog fdlg = new OpenFileDialog();
            fdlg.Title = "select schema file" ;
            fdlg.InitialDirectory = @"c:\CDEV\testdatagenerator" ;
            fdlg.Filter = "schema files(*.xsd) |*.xsd| all files(*.*) | *.*";
            fdlg.FilterIndex = 2 ;
            fdlg.RestoreDirectory = true ;
            if(fdlg.ShowDialog() == DialogResult.OK)
            {
                txtSchema.Text = fdlg.FileName ;
            }
        }

        private void button2_Click(object sender, System.EventArgs e)
        {
            dataSet1.ReadXmlSchema(txtSchema.Text);

            foreach (DataTable dTbl in dataSet1.Tables)
            {
                for(int j = 0; j <= 200; j++)
                {
                    object[] oValues = new object[dTbl.Columns.Count];
                    int i = 0 ;

                    foreach (DataColumn dColmn in dTbl.Columns)
                    {
                        switch(dColmn.DataType.ToString())

                        {
                            case "System.String":
                                oValues[i] = (string) "Castle Hampers" + j;
                                break;

                            case "System.Int32":
                                oValues[i] = (int) 100 + j;
                                break;

                            case "System.DateTime":
                                oValues[i] = new DateTime(2004,01,30).AddDays(j * 1);
                                break;

                            case "System.Decimal":
                                oValues[i] = new Decimal(10000900.99) + j;
                                break;

                            case "System.Int16":
                                oValues[i] = (short) 32767 - j;
                                break;

                            case "System.Int64":
                                oValues[i] = (long) 400 - j;
                                break;

                            case "System.Double":
                                oValues[i] = (double) 888888 - j;
                                break;

                            case "System.Single":
                                oValues[i] = (float) 4.5f + j;
                                break;

                        }

                        i = i+1;
                    }

                    dTbl.Rows.Add(oValues);
                }
            }
        }
        private void button3_Click(object sender, System.EventArgs e)
        {

            dataSet1.WriteXml(txtXml.Text,XmlWriteMode.WriteSc hema );
            MessageBox.Show("Saved");
        }
    }
}


dhol






Similar Threads
Thread Thread Starter Forum Replies Last Post
Question for Imar aspcoder BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 22 April 28th, 2008 02:40 PM
Imar! help me shankhan Dreamweaver (all versions) 1 March 20th, 2005 05:45 PM
Imar - Please look at this larry Javascript How-To 4 July 8th, 2004 12:28 PM
To Imar: Re: Sub Main shadowpug VB.NET 2002/2003 Basics 1 July 26th, 2003 02:54 PM





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