Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old September 6th, 2008, 11:35 PM
shapper
Guest
 
Posts: n/a
Default Create XML File

Hello,

How do I create the following XML file at runtime?

<?xml version="1.0" encoding="UTF-8"?>
<gallery>
<album
title="Album Title"
description="Album Description"
lgPath="../MyAlbum/Lg/"
tnPath="../MyAlbum/Tn/"
tn="Tn.jpg">

<img src="Image.jpg" title="image title" caption="image caption" /
Quote:
>
</album>
</gallery>

Thanks,
Miguel
  #2  
Old September 7th, 2008, 11:35 AM
Martin Honnen
Guest
 
Posts: n/a
Default Re: Create XML File

shapper wrote:
Quote:
How do I create the following XML file at runtime?
>
<?xml version="1.0" encoding="UTF-8"?>
<gallery>
<album
title="Album Title"
description="Album Description"
lgPath="../MyAlbum/Lg/"
tnPath="../MyAlbum/Tn/"
tn="Tn.jpg">
>
<img src="Image.jpg" title="image title" caption="image caption" /
>
</album>
</gallery>
You can do that using XmlWriter e.g.
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.NewLineOnAttributes = true;
using (XmlWriter writer = XmlWriter.Create("file.xml", settings))
{
writer.WriteStartDocument();
writer.WriteStartElement("gallery");
writer.WriteStartElement("album");
writer.WriteAttributeString("title", "Album Title");
writer.WriteAttributeString("description", "Album Description");
// write further attributes here
writer.WriteStartElement("img");
writer.WriteAttributeString("src", "Image.jpg");
// write further atrributes here
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();
}

Other options are using System.Xml.XmlDocument, or with .NET 3.5 to use
LINQ to XML (XDocument or with VB.NET XML literals).

--

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

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles