Click here to Skip to main content
Rate this: bad
good
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.
 
Thanks.
Posted 1-Jun-13 0:44am
Rate this: bad
good
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=184.107.55.15;Initial Catalog=demo;User ID=sa;Password=1947");
da.Fill(ds);
// Write to XML here
 
ds.WriteXml("D:\\output.xml", System.Data.XmlWriteMode.WriteSchema);
  Permalink  
v3
Comments
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
good
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: http://support.microsoft.com/kb/307548[^]
  Permalink  
Comments
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 BillWoodruff 300
1 Mathew Soji 274
2 Afzaal Ahmad Zeeshan 268
3 DamithSL 225
4 Sergey Alexandrovich Kryukov 205
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 3,865


Advertise | Privacy | Mobile
Web02 | 2.8.1411019.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