Click here to Skip to main content
16,021,125 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
XmlDocument doc = new XmlDocument();
            XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8","yes");
            doc.AppendChild(docNode);
            XmlNode Rule = doc.CreateElement("Rule");
            XmlAttribute Ruletag = doc.CreateAttribute("name");
            Ruletag.InnerText = "This Is My Rule";
            Rule.Attributes.Append(Ruletag);
            doc.AppendChild(Rule);
XmlNode Definition = doc.CreateElement("definition");
            Rule.AppendChild(Definition);

            XmlNode code = doc.CreateElement("code");
            XmlAttribute cname = doc.CreateAttribute("name");
            cname.InnerText = "dynamicorderagent";
            code.AppendChild(doc.CreateTextNode(txtVar.Text));
            code.Attributes.Append(cname);
            Definition.AppendChild(code);
            //XmlNode offCondition = doc.CreateElement("offCondition");
            //            offCondition.AppendChild(doc.CreateTextNode(
            foreach (TabPage tp in tabControl3.TabPages)
            {
                foreach (Control ctrl in tp.Controls)
                {
                    XmlNode eventScript = doc.CreateElement("eventScript");
                    XmlAttribute ename = doc.CreateAttribute("name");
                    XmlNode eXpres = doc.CreateElement("eventExpr");
                    XmlNode ecode = doc.CreateElement("code");
                    if (ctrl.GetType().Name == "Panel")
                    {
                        foreach (Control ctrl1 in ctrl.Controls)
                        {
                            if (ctrl1.GetType().Name == "TextBox")
                            {
                                TextBox tb = ctrl1 as TextBox;
                                //if (tb.Name == "txtVar")
                                //    continue;
                                if (tb.Name.StartsWith("Event"))
                                {
                                    ename.InnerText = tp.Name;
                                    eXpres.AppendChild(doc.CreateTextNode(tp.Name));                                    
                                }
                            }
                        }
                    }
                    if (ctrl.GetType().Name == "TextBox")
                    {
                        TextBox tb = ctrl as TextBox;
                        if (tb.Name == "txtVar")
                            continue;
                        
                        if (tb.Name.StartsWith("Code"))
                        {
                            ecode.InnerText = tb.Text;
                        }
                        eventScript.AppendChild(eXpres);
                        eventScript.AppendChild(ecode);
                        eventScript.Attributes.Append(ename);                        
                        Definition.AppendChild(eventScript);
                    }
                    
                }
            }
            string Path = @"C:\Users\SristiSanskriti\Desktop\Office\FinalTemp.XML";
            doc.Save(Path);
            MessageBox.Show("Created At :" + Path);



Result Coming Is
XML
-<eventScript name=""> 
<eventExpr/> 
<code>if( EventExg > PreEventExg) { PreEventExg=EventExg; } else { out.writeln("Mcx-Sx update Error "); if(unhedgedMCX == 0 && unhedgedMCXSX == 0) currentStrategy.turnOff("Mcx-Sx update Error",true); } </code> </eventScript>


While i want Result like this
HTML
<eventScript name="value">
<eventExpr> value </eventExpr>
<code> this value coming correct </code>


What's the problem in my code ..... please help.....thank you


[edit]unnecessary Code blocks removed[/edit]
Posted
Updated 25-May-13 0:20am
v3
Comments
Anjanee Kumar Singh 25-May-13 5:03am    
The value for code block is coming correct but value for name and eventExpr block not coming..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900