protected string ParseElement(XmlReader xr) { string elName, rlt = ""; elName = xr.Name.ToLower(); if (elName.Equals("import")) { string url = XmlReaderHelper.ReadAttribute(xr, "Url"); if (!string.IsNullOrEmpty(url) && url.IndexOf(':') < 0) { url = BaseDir + url; } CodgenXml cx = new CodgenXml(CallingAssembly); foreach (CodgenParam cp in Params) { if (cp.ParamType.Equals("globalreplace")) { CodgenParam ncp = new CodgenParam(cp.Key, cp.Value, cp.ParamType); cx.Params.Add(ncp); } } rlt = cx.ReadFile(url); } else if (elName.Equals("contentreplace")) { string key = XmlReaderHelper.ReadAttribute(xr, "Handler"); string scope = XmlReaderHelper.ReadAttribute(xr, "Scope"); string val = XmlReaderHelper.ReadContent(xr); if (string.IsNullOrEmpty(scope)) { scope = "replace"; } CodgenParam par = new CodgenParam(key, val, scope.ToLower()); Params.Add(par); //xr.Read(); //xr.Read(); } else { XmlReaderHelper.EnumAttributes(xr, delegate(string k, string v, string n) { CodgenParam par; par = new CodgenParam(k, v, n); Params.Add(par); }); } return(rlt); }
public string ParseXML(XmlReader xr) { string generator = "", method = "", rltstr; StringBuilder rlt = new StringBuilder(); if (xr.NodeType == XmlNodeType.Element) { for (int i = 0; i < xr.AttributeCount; i++) { xr.MoveToAttribute(i); if (xr.Name.Equals("Generator")) { generator = xr.Value; } else if (xr.Name.Equals("Method")) { method = xr.Value; } else { CodgenParam cp = new CodgenParam(xr.Name, xr.Value, "template"); Params.Add(cp); } } } while (xr.Read()) { //Output(xr.Name + " - " + xr.NodeType); if (xr.NodeType == XmlNodeType.CDATA || xr.NodeType == XmlNodeType.Text) { string content = xr.Value; foreach (CodgenParam cp in Params) { if (cp.ParamType.Equals("replace") || cp.ParamType.Equals("globalreplace")) { content = content.Replace(">" + cp.Key + "<", cp.Value); } } rlt.Append(content); } else if (xr.NodeType == XmlNodeType.Element) { rlt.Append(ParseElement(xr)); } } if (!string.IsNullOrEmpty(generator)) { if (string.IsNullOrEmpty(method)) { method = "Generate"; } //Type typ = Type.GetType(generator); Type typ = CallingAssembly.GetType(generator); if (typ != null) { MethodInfo mi = typ.GetMethod( method, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.GetProperty ); if (mi != null) { try { rlt = new StringBuilder(mi.Invoke(null, new object[] { rlt.ToString() }) as string); } catch (Exception err) { throw err; } } } } rltstr = rlt.ToString(); rltstr = PostRender(rltstr); RenderComplete(rltstr); return rltstr; }
protected string ParseElement(XmlReader xr) { string elName, rlt = ""; elName = xr.Name.ToLower(); if (elName.Equals("import")) { string url = XmlReaderHelper.ReadAttribute(xr, "Url"); if (!string.IsNullOrEmpty(url) && url.IndexOf(':') < 0) { url = BaseDir + url; } CodgenXml cx = new CodgenXml(CallingAssembly); foreach (CodgenParam cp in Params) { if (cp.ParamType.Equals("globalreplace")) { CodgenParam ncp = new CodgenParam(cp.Key, cp.Value, cp.ParamType); cx.Params.Add(ncp); } } rlt = cx.ReadFile(url); } else if (elName.Equals("contentreplace")) { string key = XmlReaderHelper.ReadAttribute(xr, "Handler"); string scope = XmlReaderHelper.ReadAttribute(xr, "Scope"); string val = XmlReaderHelper.ReadContent(xr); if (string.IsNullOrEmpty(scope)) { scope = "replace"; } CodgenParam par = new CodgenParam(key, val, scope.ToLower()); Params.Add(par); //xr.Read(); //xr.Read(); } else { XmlReaderHelper.EnumAttributes(xr, delegate(string k, string v, string n) { CodgenParam par; par = new CodgenParam(k, v, n); Params.Add(par); }); } return rlt; }
public string ParseXML(XmlReader xr) { string generator = "", method = "", rltstr; StringBuilder rlt = new StringBuilder(); if (xr.NodeType == XmlNodeType.Element) { for (int i = 0; i < xr.AttributeCount; i++) { xr.MoveToAttribute(i); if (xr.Name.Equals("Generator")) { generator = xr.Value; } else if (xr.Name.Equals("Method")) { method = xr.Value; } else { CodgenParam cp = new CodgenParam(xr.Name, xr.Value, "template"); Params.Add(cp); } } } while (xr.Read()) { //Output(xr.Name + " - " + xr.NodeType); if (xr.NodeType == XmlNodeType.CDATA || xr.NodeType == XmlNodeType.Text) { string content = xr.Value; foreach (CodgenParam cp in Params) { if (cp.ParamType.Equals("replace") || cp.ParamType.Equals("globalreplace")) { content = content.Replace(">" + cp.Key + "<", cp.Value); } } rlt.Append(content); } else if (xr.NodeType == XmlNodeType.Element) { rlt.Append(ParseElement(xr)); } } if (!string.IsNullOrEmpty(generator)) { if (string.IsNullOrEmpty(method)) { method = "Generate"; } //Type typ = Type.GetType(generator); Type typ = CallingAssembly.GetType(generator); if (typ != null) { MethodInfo mi = typ.GetMethod( method, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.GetProperty ); if (mi != null) { try { rlt = new StringBuilder(mi.Invoke(null, new object[] { rlt.ToString() }) as string); } catch (Exception err) { throw err; } } } } rltstr = rlt.ToString(); rltstr = PostRender(rltstr); RenderComplete(rltstr); return(rltstr); }