How can I save textbox with value in the windows forms as xml file with Rootnode and Child and sibling nodes?  
Author Message
Vaish





PostPosted: .NET Framework Data Access and Storage, How can I save textbox with value in the windows forms as xml file with Rootnode and Child and sibling nodes? Top

Hi

Please sombody help. I am trying to do the following for the past 5 days but I couldn't do it.

1. I have table and picked up one row with 70 colums as dataset
2. I used Dataset.writexml("..\test.xml")
3. All 70 colums writtern as xml but under one root element.(like below)

<root>
<1>gh</1>
<2>fg</2>
<3>fg</4>
<4>fg</4>
<5>fg</5>
</root>

4. I want the xml as below
<root>
<test1>
<1>gh</1>
<2>fg</2>
</test1>
<test2>
<3>fg</4>
<test3>
<4>fg</4>
</test3>
<5>fg</5>
</test2>
</root>
OR

How can I save textbox with value in the windows forms as xml file with Rootnode and Child and sibling nodes



.NET Development4  
 
 
CommonGenius.com





PostPosted: .NET Framework Data Access and Storage, How can I save textbox with value in the windows forms as xml file with Rootnode and Child and sibling nodes? Top

It appears that you are trying to output the xml using a custom format that is unrelated to the schema of the dataset you are working with. If that is the case, the best way to do this would be to create an XmlDocument and populate it yourself from the data being returned.

 
 
Vaish





PostPosted: .NET Framework Data Access and Storage, How can I save textbox with value in the windows forms as xml file with Rootnode and Child and sibling nodes? Top

Hi
Thank you very much for yr reply. I am new to this type of program. So can you explain a bit clear.
1. How can I populate the xml daocument from the data entered in the windows form control.
2. I have been provided with the schema, So am I able to create a dataset from the schema in order to keep the needed xml structure and populate the data from controls in the windows form.

3.If I am using custom format (Dataset.writexml("..\test.xml") to out put the collected data from windows form. Am I able to pass this output through XSLT file to get needed structure of the xml document

If any of the above method or any other easy way, please give me some syntax layout how to do it please

Many many thanks


 
 
CommonGenius.com





PostPosted: .NET Framework Data Access and Storage, How can I save textbox with value in the windows forms as xml file with Rootnode and Child and sibling nodes? Top

Yes, if you know the format you are trying to get to, you should be able to use XSLT to transform the "flat" xml you are getting into the format you need. Check out MSDN's XSLT reference.

 
 
Vaish





PostPosted: .NET Framework Data Access and Storage, How can I save textbox with value in the windows forms as xml file with Rootnode and Child and sibling nodes? Top

Hi

Thank you very much.


 
 
Luis D. Rojas





PostPosted: .NET Framework Data Access and Storage, How can I save textbox with value in the windows forms as xml file with Rootnode and Child and sibling nodes? Top

Hi Vaish,

what I recomend is to create a new DataSet in the designer and drop a DataTable on it, and start to work from it. For example, I created I simple table with the following schema - I did it visually -

<xs:element name="Tests" msdata:IsDataSet="true" msdata:UseCurrentLocale="true" msprop:Generator_UserDSName="Tests" msprop:Generator_DataSetName="Tests">

<xs:complexType>

<xs:choice minOccurs="0" maxOccurs="unbounded">

<xs:element name="Test" msprop:Generator_UserTableName="Test" msprop:Generator_RowDeletedName="TestRowDeleted" msprop:Generator_TableClassName="TestDataTable" msprop:Generator_RowChangedName="TestRowChanged" msprop:Generator_RowClassName="TestRow" msprop:Generator_RowChangingName="TestRowChanging" msprop:Generator_RowEvArgName="TestRowChangeEvent" msprop:Generator_RowEvHandlerName="TestRowChangeEventHandler" msprop:Generator_TablePropName="Test" msprop:Generator_TableVarName="tableTest" msprop:Generator_RowDeletingName="TestRowDeleting">

<xs:complexType>

<xs:sequence>

<xs:element name="TestField1" msprop:Generator_UserColumnName="TestField1" msprop:Generator_ColumnPropNameInRow="TestField1" msprop:Generator_ColumnVarNameInTable="columnTestField1" msprop:Generator_ColumnPropNameInTable="TestField1Column" type="xs:string" minOccurs="0" />

<xs:element name="TestField2" msprop:Generator_UserColumnName="TestField2" msprop:Generator_ColumnPropNameInRow="TestField2" msprop:Generator_ColumnVarNameInTable="columnTestField2" msprop:Generator_ColumnPropNameInTable="TestField2Column" type="xs:string" minOccurs="0" />

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:choice>

</xs:complexType>

</xs:element>

After that, I just linked my DataSet to a DataGrid and then I started to add items directly from my datagrid and this is the result of that operation. As you can see because of the schema, my Dataset's name is Tests and my table name is Test. Following the xml results is the code for doing that. Remember, I'm using a DataSet created visually in the designer according from what I need

< xml version="1.0" standalone="yes" >
<Tests xmlns="http://tempuri.org/Tests.xsd">
<Test>
<TestField1>2</TestField1>
<TestField2>3</TestField2>
</Test>
<Test>
<TestField1>4</TestField1>
<TestField2>5</TestField2>
</Test>
<Test>
<TestField1>67</TestField1>
<TestField2>7</TestField2>
</Test>
</Tests>

Dim ds As New Tests

m_dgvClientes.DataSource = ds.Test

Dim dlg As SaveFileDialog = New SaveFileDialog

dlg.Filter = "Xml Files (*.xml)|*.xml"

dlg.ShowDialog()

If dlg.FileName.Length > 0 Then

ds.WriteXml(dlg.FileName)

End If

Best Regards