471,605 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,605 software developers and data experts.

Creating DOM Document from Sratch

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!
Jan 29 '06 #1
1 2616


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/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXmlDocumentClassCreateElementTopic3. 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/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXmlDocumentClassCreateAttributeTopic 3.asp>
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jan 29 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Kerri McDonald | last post: by
7 posts views Thread by Russ | last post: by
2 posts views Thread by pshvarts | last post: by
6 posts views Thread by Adam Tilghman | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by CCCYYYY | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.