コード例 #1
0
//		void HandleAttrNamehandleKeyPress (object sender, System.EventArgs e)
//		{
//			if (e.KeyCode == Keys.Enter) {
//				this.ChangeAttrName();
//			}
//		}

//		void HandleAttrValuehandleKeyPress (object sender, System.EventArgs e)
//		{
//			if (e.KeyCode == Keys.Enter) {
//				this.ChangeAttrValue();
//			}
//		}

        public static void AddNameSpace(SCL scl, ComboBox nameSpaceList)
        {
            EditDialog dlg = new EditDialog(scl);

            dlg.Text = "Add new Name Space";
            dlg.L1   = "Name:";
            dlg.L2   = "URI:";
            DialogResult res = dlg.ShowDialog();

            if (res == DialogResult.OK)
            {
                if (scl.xmlns == null)
                {
                    scl.xmlns = new System.Xml.Serialization.XmlSerializerNamespaces();
                }
                scl.xmlns.Add(dlg.T1, dlg.T2);
                nameSpaceList.Items.Clear();
                for (int i = 0; i < scl.xmlns.ToArray().GetLength(0); i++)
                {
                    nameSpaceList.Items.Add("xmlns:"
                                            + scl.xmlns.ToArray()[i].Name + "="
                                            + scl.xmlns.ToArray()[i].Namespace);
                }
            }
        }
コード例 #2
0
        // TODO: We can't add new Custom Attributes due to you need an XML document object reference
        void HandleAddAttributehandleClick(object sender, System.EventArgs e)
        {
            // Add a custom Name Space before to add a new one
            if (this.scl.xmlns == null)
            {
                CustomAttributeDialog.AddNameSpace(this.scl, this.nameSpaceList);
            }

            // If no custom name space then abort
            if (this.scl.xmlns != null)
            {
                System.Xml.XmlAttribute[] attrArray;
                if (this.element.AnyAttr == null)
                {
                    attrArray = new System.Xml.XmlAttribute[1];
                }
                else
                {
                    attrArray = new System.Xml.XmlAttribute[this.element.AnyAttr.GetLength(0) + 1];
                    this.element.AnyAttr.CopyTo(attrArray, 0);
                }

                string[] ns = new string[this.scl.xmlns.ToArray().Length];
                for (int i = 0; i < ns.Length; i++)
                {
                    ns[i] = "xmlns:" + this.scl.xmlns.ToArray()[i].Name
                            + "=" + this.scl.xmlns.ToArray()[i].Namespace;
                }

                EditDialog dlg = new EditDialog(this.scl, ns);
                dlg.L1   = "Name:";
                dlg.L2   = "Value:";
                dlg.Text = "Add Custom Attribute";
                DialogResult res = dlg.ShowDialog();

                if (res == DialogResult.OK)
                {
                    if (this.xmldoc != null)
                    {
                        System.Console.WriteLine("NameSpace = "
                                                 + this.scl.xmlns.ToArray()[dlg.NameSpaceIndex]);

                        System.Console.WriteLine("Att name = " + dlg.T1);
                        System.Console.WriteLine("Att value = "
                                                 + dlg.T2);


                        System.Xml.XmlAttribute a = this.xmldoc.CreateAttribute(dlg.T1,
                                                                                this.scl.xmlns.ToArray()[dlg.NameSpaceIndex]
                                                                                .ToString());
                        a.Value = dlg.T2;

                        if (this.element.AnyAttr == null)
                        {
                            this.element.AnyAttr    = new System.Xml.XmlAttribute [1];
                            this.element.AnyAttr[1] = a;
                        }
//						else
//							this.element.AddXmlAttribute (a);

                        FillAttr();
                    }
                }
            }
        }