PC Review


Reply
Thread Tools Rate Thread

How to create an Empty XML file

 
 
=?Utf-8?B?R3VzIEd1c3RhZnNvbg==?=
Guest
Posts: n/a
 
      8th Nov 2005
I have an application that must create a new, but empty, XML file on demand.
My original approach was to copy an existing "template XML file" into the new
XML file. I found that I needed to pass through each table in the newly
created XML file and delete each row. I'm wondering if there is a better
way. For example, I can programmatically create the XML file but the problem
with this method is that the creation process is within a program.

So is there a method that uses a schema to create an empty XML file. If
there is, where is it documented? If not, what is suggested?

TIA

Gus

 
Reply With Quote
 
 
 
 
S.M. Altaf [MVP]
Guest
Posts: n/a
 
      8th Nov 2005
Gus,

Is there a reason you don't want to do this from your program? An XML file
is nothing but a text file, so you can simply create a new file with an .xml
extension, and you're done.

Unless I'm missing something from your post.

-Altaf
--------------------------------------------------------------------------------
All that glitters has a high refractive index.
www.mendhak.com


"Gus Gustafson" <(E-Mail Removed)> wrote in message
news:4C2AC5AF-7CE7-4978-9472-(E-Mail Removed)...
>I have an application that must create a new, but empty, XML file on
>demand.
> My original approach was to copy an existing "template XML file" into the
> new
> XML file. I found that I needed to pass through each table in the newly
> created XML file and delete each row. I'm wondering if there is a better
> way. For example, I can programmatically create the XML file but the
> problem
> with this method is that the creation process is within a program.
>
> So is there a method that uses a schema to create an empty XML file. If
> there is, where is it documented? If not, what is suggested?
>
> TIA
>
> Gus
>



 
Reply With Quote
 
Jim Hughes
Guest
Posts: n/a
 
      8th Nov 2005

"Gus Gustafson" <(E-Mail Removed)> wrote in message
news:4C2AC5AF-7CE7-4978-9472-(E-Mail Removed)...
>I have an application that must create a new, but empty, XML file on
>demand.
> My original approach was to copy an existing "template XML file" into the
> new
> XML file. I found that I needed to pass through each table in the newly
> created XML file and delete each row. I'm wondering if there is a better
> way. For example, I can programmatically create the XML file but the
> problem
> with this method is that the creation process is within a program.
>
> So is there a method that uses a schema to create an empty XML file. If
> there is, where is it documented? If not, what is suggested?


You could save the empty XML file as a embedded resource in your app and
then retrieve it and write it out as necessary.


 
Reply With Quote
 
=?Utf-8?B?R3VzIEd1c3RhZnNvbg==?=
Guest
Posts: n/a
 
      8th Nov 2005
Although I appreciate that I can create the XML file from my program, I would
prefer to define (once) the structure of the XML file in some manner and then
use that definition to create an empty XML file (with all of its tables and
attributes, only without data).


"S.M. Altaf [MVP]" wrote:

> Gus,
>
> Is there a reason you don't want to do this from your program? An XML file
> is nothing but a text file, so you can simply create a new file with an .xml
> extension, and you're done.
>
> Unless I'm missing something from your post.
>
> -Altaf
> --------------------------------------------------------------------------------
> All that glitters has a high refractive index.
> www.mendhak.com
>
>
> "Gus Gustafson" <(E-Mail Removed)> wrote in message
> news:4C2AC5AF-7CE7-4978-9472-(E-Mail Removed)...
> >I have an application that must create a new, but empty, XML file on
> >demand.
> > My original approach was to copy an existing "template XML file" into the
> > new
> > XML file. I found that I needed to pass through each table in the newly
> > created XML file and delete each row. I'm wondering if there is a better
> > way. For example, I can programmatically create the XML file but the
> > problem
> > with this method is that the creation process is within a program.
> >
> > So is there a method that uses a schema to create an empty XML file. If
> > there is, where is it documented? If not, what is suggested?
> >
> > TIA
> >
> > Gus
> >

>
>
>

 
Reply With Quote
 
=?Utf-8?B?R3VzIEd1c3RhZnNvbg==?=
Guest
Posts: n/a
 
      8th Nov 2005
Jim, interesting idea. Let me give some thought to that.

Thanks

"Jim Hughes" wrote:

>
> "Gus Gustafson" <(E-Mail Removed)> wrote in message
> news:4C2AC5AF-7CE7-4978-9472-(E-Mail Removed)...
> >I have an application that must create a new, but empty, XML file on
> >demand.
> > My original approach was to copy an existing "template XML file" into the
> > new
> > XML file. I found that I needed to pass through each table in the newly
> > created XML file and delete each row. I'm wondering if there is a better
> > way. For example, I can programmatically create the XML file but the
> > problem
> > with this method is that the creation process is within a program.
> >
> > So is there a method that uses a schema to create an empty XML file. If
> > there is, where is it documented? If not, what is suggested?

>
> You could save the empty XML file as a embedded resource in your app and
> then retrieve it and write it out as necessary.
>
>
>

 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      8th Nov 2005
You could use the FillSchema method of a dataAdapter to generate a dataset
with one empty table that has all the original table's schema information
intact. From there, you could use the dataset's WriteXMLSchema or WriteXML
methods to create the actual XML files you seek.


"Gus Gustafson" <(E-Mail Removed)> wrote in message
news:4C2AC5AF-7CE7-4978-9472-(E-Mail Removed)...
>I have an application that must create a new, but empty, XML file on
>demand.
> My original approach was to copy an existing "template XML file" into the
> new
> XML file. I found that I needed to pass through each table in the newly
> created XML file and delete each row. I'm wondering if there is a better
> way. For example, I can programmatically create the XML file but the
> problem
> with this method is that the creation process is within a program.
>
> So is there a method that uses a schema to create an empty XML file. If
> there is, where is it documented? If not, what is suggested?
>
> TIA
>
> Gus
>



 
Reply With Quote
 
Cowboy \(Gregory A. Beamer\)
Guest
Posts: n/a
 
      8th Nov 2005
There are a variety of ways to attack this problem:

1. The template can be empty nodes, which you start populating.
2. The template can only have the important parent nodes, which you append
data to
3. You can use a DataSet format and add information that way and then
transform with XSLT and stream back out for the user
4. A schema, which is an XML file, can be transformed to become a document.

I do not know of an autogen for XML from a schema in .NET proper. I am sure
someone has solved this as a third party tool. Try sourceforge.net and see
if any open source implementations exist.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***********************************************
Think Outside the Box!
***********************************************
"Gus Gustafson" <(E-Mail Removed)> wrote in message
news:4C2AC5AF-7CE7-4978-9472-(E-Mail Removed)...
>I have an application that must create a new, but empty, XML file on
>demand.
> My original approach was to copy an existing "template XML file" into the
> new
> XML file. I found that I needed to pass through each table in the newly
> created XML file and delete each row. I'm wondering if there is a better
> way. For example, I can programmatically create the XML file but the
> problem
> with this method is that the creation process is within a program.
>
> So is there a method that uses a schema to create an empty XML file. If
> there is, where is it documented? If not, what is suggested?
>
> TIA
>
> Gus
>



 
Reply With Quote
 
=?Utf-8?B?R3VzIEd1c3RhZnNvbg==?=
Guest
Posts: n/a
 
      8th Nov 2005
Hey, folks thanks for your thoughts. Here's what I came up with as a result
of your inputs.

1. I created an XSD file that defines the XML file. It is currently in a
directory that is relative to the location of the executable. I do like Jim's
idea (make it a resource) and I'm still thinking about it.

2. When I need to create a new instance of the XML file, I take the
following steps:

a. data_set = new DataSet ( ) ;
b. data_set.ReadXmlSchema ( XDS_path ) ;
c. directory = Path.GetDirectoryName ( XML_path ) ;
if ( ! Directory.Exists ( directory ) )
{
Directory.CreateDirectory ( directory ) ;
}
d. data_set.WriteXmlSchema ( XML_path ) ;

3. Massage the newly created XML file using ReadXml and WriteXml.

The only thing that I needed to remember (and forgot) was to check
table.Rows.Count before trying to perform

DataRow row = table.Rows [ 0 ] ;

Thought I'd pass it on.

Thanks for everyones help.

Regards,

Gus
 
Reply With Quote
 
=?Utf-8?B?R3VzIEd1c3RhZnNvbg==?=
Guest
Posts: n/a
 
      9th Nov 2005
One additional item.

When reading the XML file into a data set, use one of the ReadXML overloads
that includes the ReadXmlMode parameter set to ReadSchema. For example,

data_set.ReadXml (
path,
XmlReadMode.ReadSchema ) ;

Likewise, when writing to the XML file from the data set, use one of the
WriteXML overloads that includes the WriteXmlMode parameter set to
WriteSchema. For example,

data_set.WriteXml (
path,
XmlWriteMode.WriteSchema ) ;


Again, thanks to all for the help.

Gus

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create an empty file in a script? Michael Moser Windows XP Customization 3 19th Mar 2007 03:21 AM
Create empty file =?Utf-8?B?QW5ndXM=?= Microsoft Access VBA Modules 1 21st Sep 2006 07:25 PM
create new pst file with empty folders =?Utf-8?B?ZWQ5MjEz?= Microsoft Outlook Discussion 1 25th Jul 2005 08:47 PM
command-line way to create empty file Linda B Windows XP General 11 4th Feb 2005 05:02 AM
How to create a new empty text file? JenHu Microsoft ASP .NET 1 5th Jan 2005 09:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:14 PM.