Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: XML
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
-<eventScript name=""> 
<eventExpr/> 
<code>if( EventExg >
 
While i want Result like this
<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 24-May-13 23:57pm
Edited 25-May-13 1:20am
(no name)59.4K
v3
Comments
Anjanee Kumar SIngh at 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)

  Print Answers RSS
0 BillWoodruff 360
1 Mathew Soji 309
2 Maciej Los 270
3 DamithSL 225
4 Afzaal Ahmad Zeeshan 202
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 3,865


Advertise | Privacy | Mobile
Web02 | 2.8.1411019.1 | Last Updated 25 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100