473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to create an XML file

Hi, this is something I've been trying and I'm not capable to do.
I'm able to read from any XML file with .Net objects like XMLDoc,
XMLNode, etc, with no problem.
But when I want to create an XML file, I don't know how to use these
objects (or the ones supposed to do this), so I have to use
StreamWriter in this way:

oSW.Write("<tag value=""1"">")

I'm sure there's a best way to do this, but I haven't found yet.
I'd like some help with an example of code to write to a file an XML as
simple like this one:

<RootNode>
<tag value="1"/>
<tag value="2">
<subtag value="33" id="p"/>
</tag>
</RootNode>

Thanks in advance!

Nov 21 '05 #1
3 892
Use the XmlTextWriter class.

Note: THE FOLLOWING CODE IS UNTESTED!!

dim twr as XmlTextWriter

twr = new XmlTextWriter(PathToWrite, Nothing)
twr.Formatting = System.Xml.Formatting.Indented
twr.WriteStartDocument(True)
twr.WriteStartElement("RootNode")
twr.WriteStartElement("tag")
twr.WriteAttributeString("value", "1)
twr.WriteEndElement
twr.WriteStartElement("tag")
twr.WriteAttributeString("value", "2")
twr.WriteStartElement("subtag")
twr.WriteAttributeString("value", "33")
twr.WriteAttributeString("id", "p")
twr.WriteEndElement()
twr.WriteEndElement()
twr.WriteEndElement()
twr.Flush()
twr.Close()

Nov 21 '05 #2
Hi there,

Try this,
http://www.npsoftware.co.uk/Tutorial...stence_XML.php

Nick Pateman.

"Jordi Rico" <jo*******@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Hi, this is something I've been trying and I'm not capable to do.
I'm able to read from any XML file with .Net objects like XMLDoc,
XMLNode, etc, with no problem.
But when I want to create an XML file, I don't know how to use these
objects (or the ones supposed to do this), so I have to use
StreamWriter in this way:

oSW.Write("<tag value=""1"">")

I'm sure there's a best way to do this, but I haven't found yet.
I'd like some help with an example of code to write to a file an XML as
simple like this one:

<RootNode>
<tag value="1"/>
<tag value="2">
<subtag value="33" id="p"/>
</tag>
</RootNode>

Thanks in advance!

Nov 21 '05 #3
Thanks for all the replies!
I'll test these things tomorrow, I'll tell you if they work!

Nov 21 '05 #4

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

Similar topics

7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
4
by: I_AM_DON_AND_YOU? | last post by:
There is one more problem I am facing but didn't get the solution. In my Setup Program I am not been able to create 2 things (when the program is intalled on the client machine ) : (1) create...
8
by: barb | last post by:
So that the world at large benefits from our efforts, here is one fully documented way to use Windows Irfanview freeware to create thumbnail web galleries (http://www.irfanview.com). STEP 1:...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
15
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.