public void write (InvarContext c, TreeMap<TypeID,String> basics, String dirRootPath) throws IOException
    {
        this.context = c;
        StringBuilder code = new StringBuilder();
        code.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        code.append(br + "<schema xmlns=\"http://www.w3.org/2001/XMLSchema\"");
        code.append(" " + "xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"");
        code.append(br + "xmlns:" + nsKey + "=\"" + nsValue + "\"");
        code.append(" " + "targetNamespace=\"" + nsValue + "\"");
        code.append(">");

        code.append(br);
        TypeStruct root = c.getStructRoot();
        if (root != null)
        {
            code.append(br);
            code.append("<xs:element ");
            code.append("name=\"" + root.getAlias() + "\" ");
            code.append("type=\"" + nsKey + ":" + root.fullName(TYPE_SPLIT) + "\" ");
            code.append("/>");
        }

        code.append(br);
        codeBasics(basics, code);

        code.append(br);
        Iterator<String> i = getContext().getPackNames();
        while (i.hasNext())
        {
            InvarPackage pack = getContext().getPack(i.next());
            Iterator<String> iTypeName = pack.getTypeNames();
            while (iTypeName.hasNext())
            {
                String name = iTypeName.next();
                InvarType type = pack.getType(name);
                if (TypeID.STRUCT == type.getId())
                {
                    codeStruct((TypeStruct)type, code);
                }
                else if (TypeID.ENUM == type.getId())
                {
                    codeEnum((TypeEnum)type, code);
                }
                else
                {
                }
            }
        }
        code.append(br + "</schema>");

        File dir = new File(dirRootPath);
        if (!dir.exists())
            dir.mkdirs();
        if (dir.exists())
        {
            File file = new File(dir, "data.xsd");
            FileWriter writer = new FileWriter(file, false);
            String content = code.toString();
            writer.write(content);
            writer.close();
            System.out.println("write -> " + file.getAbsolutePath());

        }
    }