private void makeCode()
        {

            StringBuilder upperChange = new StringBuilder(built_in_type);
            upperChange[0] = built_in_type.ToUpper()[0];

            this.cName = "XsdType" + upperChange;
            GeneratorSimple gs = new GeneratorSimple(cName);
            code += gs.Code;
            code += "\r\n";
        }
示例#2
0
        private void makeCode()
        {
            StringBuilder upperChange = new StringBuilder(built_in_type);

            upperChange[0] = built_in_type.ToUpper()[0];

            this.cName = "XsdType" + upperChange;
            GeneratorSimple gs = new GeneratorSimple(cName);

            code += gs.Code;
            code += "\r\n";
        }
        private void Generation(string xsdFileName) 
        {
            string subfoler = xsdFileName.Replace(".xsd","");
            string subBuiltInPath = System.IO.Path.Combine(rootFolder_, subfoler);
            System.IO.Directory.CreateDirectory(subBuiltInPath);

            XmlSchema rootSchema = GetSchemaFromFile(xsdFileName);

            var allIncludeWriter = new StringWriter();
            bool noUseFile = false;

            try
            {
                foreach (XmlSchemaObject item in rootSchema.Items)
                {

                    var hppWriter = new StringWriter();
                    var cppWriter = new StringWriter();

                    string schemaObjectName = "";

                    if (item is XmlSchemaElement)
                    {
                        XmlSchemaElement xe = item as XmlSchemaElement;
                        schemaObjectName = xe.Name + "NoUseFile";
                        noUseFile = true;
                    }
                    else if (item is XmlSchemaComplexType)
                    {
                        

                        XmlSchemaComplexType xsct = item as XmlSchemaComplexType;

                        if (this.filterStr_.Contains(xsct.Name) || this.filterStr_ == "")
                        {

                            //debug
                            Console.WriteLine(xsct.Name);
                            CppCodeGen.Generator gen = new Generator(xsct, elementRef, includePath, elementSubstitutionRef, elementGroupRef);
                            gen.makeCode();
                            hppWriter.WriteLine(gen.HppCode);
                            cppWriter.WriteLine(gen.CppCode);
                            schemaObjectName = xsct.Name;
                        }
                    }
                    else if (item is XmlSchemaSimpleType)
                    {
                        XmlSchemaSimpleType xsst = item as XmlSchemaSimpleType;
                        CppCodeGen.GeneratorSimple gen = new GeneratorSimple(xsst);
                        hppWriter.WriteLine(gen.Code);
                        schemaObjectName = xsst.Name;
                    }

                    if (!noUseFile)
                    {
                        File.WriteAllText(Path.Combine(subBuiltInPath, schemaObjectName + ".hpp"), hppWriter.GetStringBuilder().ToString());
                        File.WriteAllText(Path.Combine(subBuiltInPath, schemaObjectName + ".cpp"), cppWriter.GetStringBuilder().ToString());
                        string includeCode = "#include <" + relFolder_ + subfoler + "\\" + schemaObjectName + ".hpp>";
                        allIncludeWriter.WriteLine(includeCode);
                    }

                }

                File.WriteAllText(Path.Combine(subBuiltInPath, "all.hpp"), allIncludeWriter.GetStringBuilder().ToString());
                //File.WriteAllText(Path.Combine(subBuiltInPath, built_in_type_subfoler + ".hpp"), writer.GetStringBuilder().ToString());
            }
            catch 
            {
                Console.WriteLine("errorOcc -----------------------------------------------------------");
                Console.ReadLine();
            }
        }