using System; using System.IO; using dotgnu.xml; public class coder { static int nodes=0; static String LastType=""; public static byte[] GetBytes(String msg) { byte[] b=new byte[msg.Length]; for(int i=0;i 1) { if(uncommented.Length < 62) start=uncommented.Length; else while((index=uncommented.IndexOf(" ",start))<=62) { if(index==-1 || index==uncommented.Length) { start=uncommented.Length; break; } else start=index+1; } String commentLine=uncommented.Substring(0,start); commentLine=commentLine.Replace('\n',' '); commentLine=commentLine.Replace('\t',' '); commented=commented+"\n///"+ (uncommented.Substring(0,start)).Replace('\n',' '); if(start==uncommented.Length)break; uncommented=uncommented.Substring(start); start=0; } return commented; } public static void processExample(XmlElement example) { String comments=""; XmlNode code=null; foreach(XmlNode nd in example.Children) { if(nd.Name=="code" && ((XmlElement)(nd)).GetAttr("lang")=="C#") { code=nd; } else { comments=comments+" "+nd.Content; } } if(code!=null) { FileStream fs=new FileStream( LastType+nodes+".cs", FileMode.OpenOrCreate, FileAccess.Write); comments="/* \n"+comments+"*/\n\n"; // comments=SetComments(comments)+"\n\n"; // funky comment style fs.Write(GetBytes(comments),0,comments.Length); fs.Write(GetBytes(code.Content),0,code.Content.Length); fs.Close(); nodes++; } } public static void printRecursive(XmlNode node) { if(node.ElementType==XmlElementType.XML_ELEMENT_NODE) { XmlElement el=(XmlElement)node; if(el.Name=="Type") { LastType=el.GetAttr("FullName"); nodes=0; } if(el.Name=="example") { processExample(el); return; } } if(node.GetFirstChild()!=null) { printRecursive(node.GetFirstChild()); } if(node.GetNextSibling()!=null) { printRecursive(node.GetNextSibling()); } } public static void Main(String[] args) { String file="All.xml"; if(args.Length==1) file=args[0]; XmlDoc dc=XmlParser.Parse(file); dc.Normalize(); printRecursive(dc); } }