... System.Xml

    Date: 11/10/04 (C Sharp)    Keywords: xml, microsoft

    Ive been grinding my teeth on this one for the past hour. Even taking cuts from MS code and others i get the same results.

     using System;

    namespace
    TocGen

    {
        ///


        /// Summary description for Stringys.
        ///

        public class Stringys
        {
            public enum OOOXMLType
            {
                content,
                meta,
                settings,
                styles,
            }

            #region
    Helpers

            ///
            /// Writes a FULL attribute to a tag on an XML Text Writer
            ///

            /// Supplied Writer
            /// Attribute Prefix
            /// Attribute Name
            /// Attribute Namespace
            /// Attribute Value
            public static void WriteFullAttribute(System.Xml.XmlTextWriter oXw, string pre, string n, string ns, string val)
            {
                
                oXw.WriteStartAttribute(pre,n,ns);
                if (val!=null)
                    oXw.WriteString(val);
                oXw.WriteEndAttribute();
            }
            #endregion
            
                 public static void StartXMLDocument(OOOXMLType Dt, System.Xml.XmlTextWriter oXw)
            {    
                // Enable Dreamweaver Styled Formatting
                oXw.Indentation=2;
                oXw.IndentChar=Char.Parse(" ");
                oXw.Formatting=System.Xml.Formatting.Indented;
                
                //
                oXw.WriteStartDocument();
            
                switch (Dt)
                {
                    case OOOXMLType.content:
                        //
                        oXw.WriteDocType("office:document-content","-//OpenOffice.org//DTD OfficeDocument 1.0//EN","office.dtd",null);

                        //
                        // xmlns:text="http://openoffice.org/2000/text" xmlns:table="http://openoffice.org/2000/table" xmlns:draw="http://openoffice.org/2000/drawing"
                        // xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:number="http://openoffice.org/2000/datastyle"
                        // xmlns:svg="http://www.w3.org/2000/svg" xmlns:chart="http://openoffice.org/2000/chart" xmlns:dr3d="http://openoffice.org/2000/dr3d"
                        // xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="http://openoffice.org/2000/form" xmlns:script="http://openoffice.org/2000/script"
                        // office:class="text" office:version="1.0">
                        oXw.WriteStartElement("office", "document-settings", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", null, "http://openoffice.org/2000/office", null);  //ERROR ALLWAYS HAPPENS HERE
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "style", "http://openoffice.org/2000/style", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "text", "http://openoffice.org/2000/text", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "table", "http://openoffice.org/2000/table", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "draw", "http://openoffice.org/2000/drawing", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "fo", "http://www.w3.org/1999/XSL/Format", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "xlink", "http://www.w3.org/1999/xlink", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "number", "http://openoffice.org/2000/datastyle", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "svg", "http://www.w3.org/2000/svg", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "chart", "http://openoffice.org/2000/chart", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "dr3d", "http://openoffice.org/2000/dr3d", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "math", "http://www.w3.org/1998/Math/MathML", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "form", "http://openoffice.org/2000/form", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "script", "http://openoffice.org/2000/script", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "office", "class", null, "text");
                        TocGen.Stringys.WriteFullAttribute(oXw, "office", "version", null, "1.0");
                        oXw.WriteEndElement();

                        
    break;


                    case OOOXMLType.meta:
                        //
                        oXw.WriteDocType("office:document-meta","-//OpenOffice.org//DTD OfficeDocument 1.0//EN","office.dtd",null);

                        //
                        // xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="http://openoffice.org/2000/meta" office:version="1.0">
                        oXw.WriteStartElement("office", "document-settings", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "office", "http://openoffice.org/2000/office", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "xlink", "http://www.w3.org/1999/xlink", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "dc", "http://purl.org/dc/elements/1.1/", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "meta", "http://openoffice.org/2000/meta", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "office", "version", null, "1.0");
                        oXw.WriteEndElement();

                        break;

                    case OOOXMLType.settings:
                        //
                        oXw.WriteDocType("office:document-settings","-//OpenOffice.org//DTD OfficeDocument 1.0//EN","office.dtd",null);
                                
                        //
                        // xmlns:config="http://openoffice.org/2001/config" office:version="1.0">
                        oXw.WriteStartElement("office", "document-settings", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "office", "http://openoffice.org/2000/office", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "xlink", "http://www.w3.org/1999/xlink", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "config", "http://openoffice.org/2001/config", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "office", "version", null, "1.0");
                        oXw.WriteEndElement();

                        
    break;


                    case OOOXMLType.styles:
                        //
                        oXw.WriteDocType("office:document-styles","-//OpenOffice.org//DTD OfficeDocument 1.0//EN","office.dtd",null);

                        // 
                        // xmlns:text="http://openoffice.org/2000/text" xmlns:table="http://openoffice.org/2000/table" xmlns:draw="http://openoffice.org/2000/drawing"
                        // xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:number="http://openoffice.org/2000/datastyle"
                        // xmlns:svg="http://www.w3.org/2000/svg" xmlns:chart="http://openoffice.org/2000/chart" xmlns:dr3d="http://openoffice.org/2000/dr3d"
                        // xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="http://openoffice.org/2000/form" xmlns:script="http://openoffice.org/2000/script"
                        // office:version="1.0">
                        oXw.WriteStartElement("office", "document-settings", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "office", "http://openoffice.org/2000/office", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "style", "http://openoffice.org/2000/style", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "text", "http://openoffice.org/2000/text", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "table", "http://openoffice.org/2000/table", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "draw", "http://openoffice.org/2000/drawing", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "fo", "http://www.w3.org/1999/XSL/Format", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "xlink", "http://www.w3.org/1999/xlink", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "number", "http://openoffice.org/2000/datastyle", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "svg", "http://www.w3.org/2000/svg", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "chart", "http://openoffice.org/2000/chart", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "dr3d", "http://openoffice.org/2000/dr3d", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "math", "http://www.w3.org/1998/Math/MathML", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "form", "http://openoffice.org/2000/form", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "xmlns", "script", "http://openoffice.org/2000/script", null);
                        TocGen.Stringys.WriteFullAttribute(oXw, "office", "version", null, "1.0");
                        oXw.WriteEndElement();

                        break;

                    default:
                        throw new System.NotSupportedException();
                }
                        
                oXw.Flush();
                        
                //oMs.Position = 0;
                //System.IO.StreamReader oSr = new System.IO.StreamReader(oMs);
                //#if (DEBUG)
                //System.Windows.Forms.MessageBox.Show(oSr.ReadToEnd());
                //#endif
            }
        }
    }

    I allways receive the following error:
    An unhandled exception of type 'System.ArgumentException' occurred in system.xml.dll
    Additional information: An undefined prefix is in use.'DefaultDomain': Loaded 'c:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll', No symbols loaded.
    'TocGen': Loaded 'C:\Documents and Settings\Glenn\My Documents\Visual Studio Projects\WhelenOOO\TocGen\bin\Debug\TocGen.exe', Symbols loaded.
    'TocGen.exe': Loaded 'c:\windows\assembly\gac\system.windows.forms\1.0.5000.0__b77a5c561934e089\system.windows.forms.dll', No symbols loaded.
    'TocGen.exe': Loaded 'c:\windows\assembly\gac\system\1.0.5000.0__b77a5c561934e089\system.dll', No symbols loaded.
    'TocGen.exe': Loaded 'c:\windows\assembly\gac\system.drawing\1.0.5000.0__b03f5f7f11d50a3a\system.drawing.dll', No symbols loaded.
    'TocGen.exe': Loaded 'c:\windows\assembly\gac\system.xml\1.0.5000.0__b77a5c561934e089\system.xml.dll', No symbols loaded.
    An unhandled exception of type 'System.ArgumentException' occurred in system.xml.dll

    Additional information: An undefined prefix is in use.

    Any idea at all why? Ive searched MSDN and several other sites... No dice. Any help would be appreciated.

     

    Source: http://www.livejournal.com/community/csharp/21413.html

« fast set || Interfaces »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home