Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: .NET2.0 C#2.0 .NET3.0 C#3.0 VS2008 , +
Hi Experts,
Can anybody suggest me a best approach on how to generate a XML file programmatically using C# other than XmlReader/XmlWriter? (so that parsing it should be easier).
Basically, it is a Xml Hbm mapping file for NHibernate. Any .NET Api available for reading/writing Hbm files like for Xaml we have XamlReader/XamlWriter.
Posted 1-Jun-13 0:44am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

System.Data.DataSet ds = new System.Data.DataSet();
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter("Select * from demo", "Data Source=;Initial Catalog=demo;User ID=sa;Password=1947");
// Write to XML here
ds.WriteXml("D:\\output.xml", System.Data.XmlWriteMode.WriteSchema);
Mohammed Hameed at 1-Jun-13 6:05am
I dont want to use a DataSet. I want to create HBM file tags like:

<param name="sequence">MyClass_SEQ</param>

<property name="Prop1" column="Column1" type="Int32"/>
<property name="Prop2" column="Column2" type="Int32"/>

Mohammed Hameed at 1-Jun-13 8:27am
Check Solution 2. That's what I was looking for.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Just checked XmlTextReader class, wow it fits perfectly to my requirements.
Brief introduction: XmlTextReader provides direct parsing and tokenizing of XML and implements the XML 1.0 specification as well as the namespaces in the XML specification from the World Wide Web Consortium (W3C). This article provides fast, tokenized stream access to XML rather than using an object model such as the XML Document Object Model (DOM).
For further information, refer this link:[^]
H.Brydon at 2-Jun-13 1:06am
I'm puzzled why you consider this an answer to your question. Your question asked about writing XML files, this answer you provided here describes an XML reader.
Mohammed Hameed at 2-Jun-13 3:51am
Yes I have to read an existing XML file and then while reading prepare and write another XML. May be my question was not much clear. My apologies for that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 210
2 BillWoodruff 205
3 Jochen Arndt 180
4 Sergey Alexandrovich Kryukov 165
0 OriginalGriff 5,130
1 DamithSL 4,157
2 Maciej Los 3,650
3 Kornfeld Eliyahu Peter 3,460
4 Sergey Alexandrovich Kryukov 2,811

Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 1 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100