Creating DOM Document from Sratch

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JackieWilson

    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(dump File, FileMode.OpenOr Create,
    FileAccess.Writ e);

    XmlTextWriter w = new XmlTextWriter(f s, Encoding.UTF8);

    w.Formatting = Formatting.Inde nted;

    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!


  • Martin Honnen

    #2
    Re: Creating DOM Document from Sratch



    JackieWilson wrote:

    [color=blue]
    > 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".[/color]

    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/frlrfSystemXmlX mlDocumentClass CreateElementTo pic3.asp>
    allows you to pass in the prefix, local name and the namespace URI
    XmlElement element =
    someDocument.Cr eateElement("ht ml", "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/frlrfSystemXmlX mlDocumentClass CreateAttribute Topic3.asp>


    --

    Martin Honnen --- MVP XML

    Comment

    Working...