Creating DOM Document from Sratch

J

JackieWilson

Hello!

I', trying to create DOM based XML document. First I create XmlDocument
object and then read other XML DOM Document and modifie the first one.
I'm putting Noden and Attributes tto the first XML DOM document when needed.
Everything seems to be allrigth but when I trying to save the scratch based
DOM Document wirj following code I get an error: "Cannot use a prefix with
an empty namespace".

FileStream fs = new FileStream(dumpFile, FileMode.OpenOrCreate,
FileAccess.Write);

XmlTextWriter w = new XmlTextWriter(fs, Encoding.UTF8);

w.Formatting = Formatting.Indented;

document.Save(w);

w.Flush();

w.Close();

What is wrong adn what this "Cannot use a prefix with an empty namespace"
errormessage measn? Is it not allowed to create in C# a XML DOM document
without usig Load method first.

Cheers!
 
M

Martin Honnen

JackieWilson wrote:

I', trying to create DOM based XML document. First I create XmlDocument
object and then read other XML DOM Document and modifie the first one.
I'm putting Noden and Attributes tto the first XML DOM document when needed.
Everything seems to be allrigth but when I trying to save the scratch based
DOM Document wirj following code I get an error: "Cannot use a prefix with
an empty namespace".

We need to see what you are trying to create with the DOM then, it
sounds as if you are using namespaces or prefixes in qualified names
incorrectly.
Try to reduce your code to the minimum that causes the error then show
us the code.
Make sure if you want to create XML with namespaces, e.g. elements in a
namespace that you use namespace aware overloads of CreateElement e.g.
<http://msdn.microsoft.com/library/d...temXmlXmlDocumentClassCreateElementTopic3.asp>
allows you to pass in the prefix, local name and the namespace URI
XmlElement element =
someDocument.CreateElement("html", "p",
"http://www.w3.org/1999/xhtml");
There are also namespace aware overloads of CreateAttribute
<http://msdn.microsoft.com/library/d...mXmlXmlDocumentClassCreateAttributeTopic3.asp>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top