gone (lifewarped) wrote in csharp,
gone
lifewarped
csharp

  • Mood:

... System.Xml

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>
    /// Summary description for Stringys.
    /// </summary>
    public class Stringys
    {
        public enum OOOXMLType
        {
            content,
            meta,
            settings,
            styles,
        }

        #region
Helpers

        /// <summary>
        /// Writes a FULL attribute to a tag on an XML Text Writer
        /// </summary>
        /// <param name="oXw">Supplied Writer</param>
        /// <param name="pre">Attribute Prefix</param>
        /// <param name="n">Attribute Name</param>
        /// <param name="ns">Attribute Namespace</param>
        /// <param name="val">Attribute Value</param>
        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;
            
            // <?xml ... ?>
            oXw.WriteStartDocument();
        
            switch (Dt)
            {
                case OOOXMLType.content:
                    // <!DOCTYPE office:document-content PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "office.dtd">
                    oXw.WriteDocType("office:document-content","-//OpenOffice.org//DTD OfficeDocument 1.0//EN","office.dtd",null);

                    // <office:document-content xmlns:office="http://openoffice.org/2000/office" xmlns:style="http://openoffice.org/2000/style"
                    // 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:
                    // <!DOCTYPE office:document-meta PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "office.dtd">
                    oXw.WriteDocType("office:document-meta","-//OpenOffice.org//DTD OfficeDocument 1.0//EN","office.dtd",null);

                    // <office:document-meta xmlns:office="http://openoffice.org/2000/office" xmlns:xlink="http://www.w3.org/1999/xlink"
                    // 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:
                    // <!DOCTYPE office:document-settings PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "office.dtd">
                    oXw.WriteDocType("office:document-settings","-//OpenOffice.org//DTD OfficeDocument 1.0//EN","office.dtd",null);
                            
                    // <office:document-settings xmlns:office="http://openoffice.org/2000/office" xmlns:xlink="http://www.w3.org/1999/xlink"
                    // 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:
                    // <!DOCTYPE office:document-styles PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "office.dtd">
                    oXw.WriteDocType("office:document-styles","-//OpenOffice.org//DTD OfficeDocument 1.0//EN","office.dtd",null);

                    // <office:document-styles xmlns:office="http://openoffice.org/2000/office" xmlns:style="http://openoffice.org/2000/style"
                    // 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.

 

Subscribe
  • Post a new comment

    Error

    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 7 comments