Click here to Skip to main content
15,920,896 members
Home / Discussions / C#
   

C#

 
GeneralDisabled Button still accepts presses Pin
mikey_g6-Jan-05 5:45
mikey_g6-Jan-05 5:45 
GeneralRe: Disabled Button still accepts presses Pin
Nick Parker6-Jan-05 7:04
protectorNick Parker6-Jan-05 7:04 
GeneralRe: Disabled Button still accepts presses Pin
mikey_g6-Jan-05 23:33
mikey_g6-Jan-05 23:33 
GeneralXML Bulk Loader (SQLXML 3.0) Pin
exhaulted6-Jan-05 3:43
exhaulted6-Jan-05 3:43 
GeneralRe: XML Bulk Loader (SQLXML 3.0) Pin
perlmunger6-Jan-05 5:37
perlmunger6-Jan-05 5:37 
GeneralInfragistics UltraCalendarInfo control Pin
eliea6-Jan-05 1:45
eliea6-Jan-05 1:45 
GeneralRe: Infragistics UltraCalendarInfo control Pin
Nick Parker6-Jan-05 6:50
protectorNick Parker6-Jan-05 6:50 
Generalmodifying xml field data's using c# Pin
dhol6-Jan-05 1:42
dhol6-Jan-05 1:42 
Hi I have done aprogram in c# such that , my program reads a schema file and automatically loads data into a xml file.

ex:
consider the following schema


<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<xs:schema id="NewDataSet" xmlns:xs="http://://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:Locale="en-AU">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="vw_forecast">
<xs:complexType>
<xs:sequence>
<xs:element name="billto_name" type="xs:string" minOccurs="0" />
<xs:element name="dividend" type="xs:float" minOccurs="0" />
<xs:element name="section" type="xs:double" minOccurs="0" />

</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
</NewDataSet>


We can see that there are three fields namely billto_name, dividend and section.

so my program reads this schema file and loads data automatically by obtaining the following xml file


<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:Locale="en-AU">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="vw_forecast">
<xs:complexType>
<xs:sequence>
<xs:element name="billto_name" type="xs:string" minOccurs="0" />
<xs:element name="dividend" type="xs:float" minOccurs="0" />
<xs:element name="section" type="xs:double" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<vw_forecast>
<billto_name>Castle Hampers0</billto_name>
<dividend>4.5</dividend>
<section>888888</section>
</vw_forecast>
<vw_forecast>
<billto_name>Castle Hampers1</billto_name>
<dividend>5.5</dividend>
<section>888889</section>
</vw_forecast>
<vw_forecast>
<billto_name>Castle Hampers2</billto_name>
<dividend>6.5</dividend>
<section>888888</section>
</vw_forecast>
<vw_forecast>
<billto_name>Castle Hampers3</billto_name>
<dividend>7.5</dividend>
<section>8888890</section>
</vw_forecast>
<vw_forecast>
<billto_name>Castle Hampers4</billto_name>
<dividend>8.5</dividend>
<section>888891</section>
</vw_forecast>

</NewDataSet>


we can see the values

Now my requirement is that I have another xml file with a single field name "billto_name". with some meaningful values. So I have to program such that if the schema contains a "billto_name" field then load those data's into the result xml.


<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:Locale="en-AU">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="billtoname">
<xs:complexType>
<xs:sequence>
<xs:element name="billto_name" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<billtoname>
<billto_name>ACCOUNTS CODES ONLY</billto_name>
</billtoname>
<billtoname>
<billto_name>ACCOUNTS CODES ONLY</billto_name>
</billtoname>
<billtoname>
<billto_name>AERIAL PRODUCT RANGE</billto_name>
</billtoname>
<billtoname>
<billto_name>AFL LICENCED PRODUCT</billto_name>
</billtoname>
<billtoname>
<billto_name>AUST RUGBY UNION</billto_name>
</billtoname>
</NewDataSet>

so the values such as AUST RUGBY UNION , AFL LICENCED PRODUCT EVERYTHING SHOUYLD BE INSERTED INTO THE PREVIOUS XML FILE FOR THAT FIELD ALONE.


This is my requirement. I tried a lot but i couldnt suceed

Here is my part of the coding. pls help me out to do this.

private void button2_Click(object sender, System.EventArgs e)
{
dataSet1.ReadXmlSchema(txtSchema.Text);
foreach (DataTable dTbl in dataSet1.Tables)
{
for(int j = 0; j <= 11; j++)
{
object[] oValues = new object[dTbl.Columns.Count];
int i = 0;

string fileName = "C:\\CDEV\\testdatagenerator\\billtoname.xml";
XmlTextReader xtr = new XmlTextReader(fileName);

foreach (DataColumn dColmn in dTbl.Columns)
{

try
{

xtr = new XmlTextReader("C:\\CDEV\\testdatagenerator\\billtoname.xml");
while(xtr.Read())
{
switch (xtr.NodeType)
{ case XmlNodeType.Element:
if((xtr.NodeType == XmlNodeType.Element) && (xtr.Name == "billto_name") )
{
oValues[i] = xtr.Value;
}
break;
}
}
}
finally
{
if (xtr != null)
{
xtr.Close();
}

}

switch(dColmn.DataType.ToString())
{
case "System.String":
oValues[i] = (string) "sachin" + 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.IgnoreSchema );
MessageBox.Show("Saved");
}


Hope anyone will help me .

santhosh



GeneralRe: modifying xml field data's using c# Pin
perlmunger6-Jan-05 5:43
perlmunger6-Jan-05 5:43 
GeneralRe: modifying xml field data's using c# Pin
dhol6-Jan-05 16:38
dhol6-Jan-05 16:38 
GeneralRe: modifying xml field data's using c# Pin
perlmunger7-Jan-05 6:27
perlmunger7-Jan-05 6:27 
GeneralRe: modifying xml field data's using c# Pin
dhol7-Jan-05 17:05
dhol7-Jan-05 17:05 
GeneralMethod return Value Pin
webhay5-Jan-05 23:43
webhay5-Jan-05 23:43 
GeneralRe: Method return Value Pin
Stefan Troschuetz5-Jan-05 23:59
Stefan Troschuetz5-Jan-05 23:59 
GeneralRe: Method return Value Pin
haimlz6-Jan-05 1:02
haimlz6-Jan-05 1:02 
GeneralRe: Method return Value Pin
Salil Khedkar6-Jan-05 1:07
Salil Khedkar6-Jan-05 1:07 
GeneralXmlDocument Write problems and Add Identation Help! Pin
Chua Wen Ching5-Jan-05 23:40
Chua Wen Ching5-Jan-05 23:40 
GeneralRe: XmlDocument Write problems and Add Identation Help! Pin
Stanimir_Stoyanov6-Jan-05 0:07
Stanimir_Stoyanov6-Jan-05 0:07 
GeneralRe: XmlDocument Write problems and Add Identation Help! Pin
J4amieC6-Jan-05 3:03
J4amieC6-Jan-05 3:03 
GeneralRe: XmlDocument Write problems and Add Identation Help! Pin
Chua Wen Ching6-Jan-05 13:34
Chua Wen Ching6-Jan-05 13:34 
GeneralList View items - exporting and importing data Pin
Stanimir_Stoyanov5-Jan-05 22:43
Stanimir_Stoyanov5-Jan-05 22:43 
GeneralRe: List View items - exporting and importing data Pin
Patric_J6-Jan-05 10:55
Patric_J6-Jan-05 10:55 
GeneralPrint without preview in C# Pin
gbess5-Jan-05 22:39
gbess5-Jan-05 22:39 
Generalimage screensaver with mem probs Pin
Steven_T5-Jan-05 20:41
Steven_T5-Jan-05 20:41 
GeneralRe: image screensaver with mem probs Pin
perlmunger6-Jan-05 6:11
perlmunger6-Jan-05 6:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.