|
-
Jul 19th, 2009, 06:11 AM
#1
Thread Starter
New Member
[RESOLVED] Basic Writing to XML
Hi everyone,
I have some data which I need to export into an XML file. The file syntax is:
HTML Code:
<functions type="0">
<plugin name="Astring">
<plugindomain name="TEXT">
<computer name="TEXT" optionstxt="TEXT" note="TEXT" />
<computer name="TEXT" optionstxt="TEXT" note="TEXT" />
</plugindomain>
</plugin>
<plugin name="Bstring">
<plugindomain name="TEXT">
<computer name="TEXT" optionstxt="TEXT" note="TEXT" />
<computer name="TEXT" optionstxt="TEXT" note="TEXT" />
</plugindomain>
</plugin>
</functions>
The data I have is listed in an EXCEL sheet and I can loop through all the different data without problem. I just do not know how to write to XML with elements, nodes etc
The above shows two plugin sections, which will contain another child called plugindomain, under the plugindomain node I need to then add a load of computer nodes.
Is there a way to complete this? I have never used XML before progrmatically with VB2005, so any assistance is greatly received!
Thanks,
-
Jul 19th, 2009, 07:16 AM
#2
Re: Basic Writing to XML
vb.net Code:
Using writer As XmlWriter = XmlWriter.Create("file path here") writer.WriteStartElement("functions") writer.WriteAttributeString("type", "0") writer.WriteStartElement("plugin") writer.WriteAttributeString("name", "Astring") writer.WriteStartElement("plugindomain") writer.WriteAttributeString("name", "TEXT") writer.WriteStartElement("computer") writer.WriteAttributeString("name", "TEXT") writer.WriteAttributeString("optionstxt", "TEXT") writer.WriteAttributeString("note", "TEXT") writer.WriteEndElement() writer.WriteStartElement("computer") writer.WriteAttributeString("name", "TEXT") writer.WriteAttributeString("optionstxt", "TEXT") writer.WriteAttributeString("note", "TEXT") writer.WriteEndElement() writer.WriteEndElement() writer.WriteEndElement() writer.WriteStartElement("plugin") writer.WriteAttributeString("name", "Bstring") writer.WriteStartElement("plugindomain") writer.WriteAttributeString("name", "TEXT") writer.WriteStartElement("computer") writer.WriteAttributeString("name", "TEXT") writer.WriteAttributeString("optionstxt", "TEXT") writer.WriteAttributeString("note", "TEXT") writer.WriteEndElement() writer.WriteStartElement("computer") writer.WriteAttributeString("name", "TEXT") writer.WriteAttributeString("optionstxt", "TEXT") writer.WriteAttributeString("note", "TEXT") writer.WriteEndElement() writer.WriteEndElement() writer.WriteEndElement() writer.WriteEndElement() End Using
-
Jul 19th, 2009, 08:26 AM
#3
Re: Basic Writing to XML
Just note that that code will specifically create the XML you posted. Obviously you'll need to generalise the code to handle the general case. For instance, you have multiple 'plugin' elements so you would need to use a loop to create them. You also have multiple 'computer' elements so you'd need to nest another loop to create them.
-
Jul 20th, 2009, 02:31 AM
#4
Thread Starter
New Member
Re: Basic Writing to XML
Thanks jmcilhinney!! Just what I was looking for.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|