473,587 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how 2 generate xml file

Pls help me out
I am trying to generate xml file via XmlDocument class. I ceated a
XmlDocument instance, how can I convert it to a physical xml file(e.g.
test.xml)?
following is the code:
//add root
XmlElement rootNode = xmlDoc.CreateEl ement("root");
rootNode.SetAtt ribute("root", root);
xmlDoc.AppendCh ild(rootNode);

// Add node1
XmlElement sitNode = xmlDoc.CreateEl ement("node1");
node1.SetAttrib ute("node1", "node1");
xmlDoc.Document Element.AppendC hild(node1);

Seems it will need some I/O related API. But I cannot find it.
I am new to C#, pls don't angry with my simple question.

thanks
Blair
Nov 12 '05 #1
2 1302


Blair Chen wrote:

I am trying to generate xml file via XmlDocument class. I ceated a
XmlDocument instance, how can I convert it to a physical xml file(e.g.
test.xml)?
following is the code:
//add root
XmlElement rootNode = xmlDoc.CreateEl ement("root");
rootNode.SetAtt ribute("root", root);
xmlDoc.AppendCh ild(rootNode);

// Add node1
XmlElement sitNode = xmlDoc.CreateEl ement("node1");
node1.SetAttrib ute("node1", "node1");
xmlDoc.Document Element.AppendC hild(node1);


xmlDoc.Save("fi le.xml")
is one way, the Save method has several overloads to save to a stream or
a TextWriter or an XmlWriter.
There are also a further method
xmlDoc.WriteTo( xmlWriter)
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
Oh, and a little known and unmentioned over-ride I have available in
datatables is writeXml("FileP athandName") where you don't need a previously
opened stream or anything like that, just write the file. Same for readXML.
"Martin Honnen" <ma*******@yaho o.de> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..


Blair Chen wrote:

I am trying to generate xml file via XmlDocument class. I ceated a
XmlDocument instance, how can I convert it to a physical xml file(e.g.
test.xml)?
following is the code:
//add root
XmlElement rootNode = xmlDoc.CreateEl ement("root");
rootNode.SetAtt ribute("root", root);
xmlDoc.AppendCh ild(rootNode);

// Add node1
XmlElement sitNode = xmlDoc.CreateEl ement("node1");
node1.SetAttrib ute("node1", "node1");
xmlDoc.Document Element.AppendC hild(node1);


xmlDoc.Save("fi le.xml")
is one way, the Save method has several overloads to save to a stream or a
TextWriter or an XmlWriter.
There are also a further method
xmlDoc.WriteTo( xmlWriter)
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2333
by: Tim:. | last post by:
Hi Can someone tell me how I generate a new XML file that I can then use with an XSLT file. I am trying to use an XML file generated from Microsoft Project or even better generate an XML file from the project file (MPP File) itself. Which I can then use with an XSLT file I am new to XML and want to create a project viewer using XML, ASP and...
0
2407
by: Almoni | last post by:
Hi, I have a few .xsd files that include each other in the following way: <!-- lets call the main schema file AA.xsd and it includes BB.xsd inside it --> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
4
2071
by: Stephen | last post by:
I need to generate input XML for another application by serialising classes defined in an XSD document. The code below will generate the XML I require but I need to generate this in memory rather than creating a file. I assume I should be using System.IO.MemoryStream but can't get this to work. ' XML will be serialized to file.xml, in...
2
6923
by: PeterW | last post by:
I have an xml file from which I want to generate an xsd schema and at a later stage a cs class. The xml file has a mix of defined namespaces and also an empty namespace. These are defined as follows: <silcn:silcn xmlns:silcn='http://silcn.org/200309' xmlns='http://xmlprobe.com/200312'> it contains an element <report> off the root and...
0
2248
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional assistance. I say additional because I've already had help which is greatly appreciated. I do try to take the time and understand the provided script...
6
3067
by: comp.lang.php | last post by:
/** * Generate the random security image * * @access public * @param $willUseFilePath (default false) boolean to determine if you will be using a file path * @param mixed $filePath (optional) file path to store image resource object contents * @see actual_path */
13
2940
by: vm98123 | last post by:
Hi, could someone please give me a clue to this one: I do have an xml-File and an xslt-File so that a browser can display the xml-file. What I am trying to do is convert this to pdf or tiff. I know that with fop you can convert xml + xsl-fo to pdf.
82
4567
by: robert bristow-johnson | last post by:
here is a post i put out (using Google Groups) that got dropped by google: i am using gcc as so: $ gcc -v Using built-in specs. Target: i386-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man -- infodir=/usr/share/info --enable-shared --enable-threads=posix -- enable-checking=release --with-system-zlib...
2
7377
by: bthubbard | last post by:
This may not be the best group in which to post this. If there is a better location please direct me there. I have been experimenting with Sandcastle to generate CHM help file documentation for some of our projects. I can configure a project(s) to generate the required XML Documentation file by editing the project properties via VS or I...
23
2388
by: Geoff Cox | last post by:
Hello, Is it possible to use php to generate different menus for users who have access to files in different folders? For example, user Fred might be able to access files in folders A, B and F, whilst use Jane might be able to access files in folders A, D and E. I would want each user to only see text and links relevant to the files in...
0
7923
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7852
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8221
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.