Help with C# and XML Transformations

I'm trying to convert a comma delimited text file into an XML document then apply a schema to the XML to ensure all the data coming in is of the proper format.  I've been using the XmlCsvReader class (found on MSDN) to convert the text file into the XML document.  The only problem I'm having is that the XmlCsvReader does not insert the xml declaration on the first line or  the namespace in the root element of the new XML document.  As a result, when I attempt to apply the schema, none of the elements are recognized.

How can I insert the XML declaration and the namespace into the new XML document?

Thank you,
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If you are using the sample code from

then add these after doc.Load(reader),

XmlElement root = doc.DocumentElement;
XmlDeclaration xmldecl = doc.CreateXmlDeclaration("1.0",null,null);
doc.InsertBefore(xmldecl, root);

and now write the xml file...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mglace390Author Commented:
That worked wonderfully however I'm still dealing with this namespace issue.  I can't get my namespace to show up in my root element.  Any ideas?
mglace390Author Commented:
Nevermind I figured it out.

XmlElement root = doc.DocumentElement;
root.SetAttribute("xmlns", "urn:namespace");

Thank you
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.