Click here to Skip to main content
15,897,334 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear friends,,
I want to add an Extra node to my XML given below...I want to add a new AttributeItem at any of the attribute row based on Index..

Please help me ,,,,what I have tried is given below in code....


XML
<MainTable width="500px">
  <MainRow Heading="User Information">
    <AttributeRow>
      <AttributeItem AttributeType="ID" Attributelabel="Employee ID" AttributeObject="ATLEmployeeInfo" AttributeDataType="string" AttributeCMValue="" AttributeContolItem="TextBox" />
      <AttributeItem AttributeType="EmpType" Attributelabel="Employee Type" AttributeObject="ATLEmployeeInfo" AttributeDataType="string" AttributeCMValue="" AttributeContolItem="TextBox" />
    </AttributeRow>
    <AttributeRow>
      <AttributeItem AttributeType="Busi_Fax" Attributelabel="Business Fax No." AttributeObject="ATLEmployeeInfo" AttributeDataType="string" AttributeCMValue="" AttributeContolItem="TextBox" />
    </AttributeRow>
    <AttributeRow>
      <AttributeItem AttributeType="City" Attributelabel="City" AttributeObject="ATLEmployeeInfo" AttributeDataType="string" AttributeCMValue="" AttributeContolItem="DropDownList" />
    </AttributeRow>
    <AttributeRow>
      <AttributeItem AttributeType="EmpName" Attributelabel="Employee Name" AttributeObject="ATLEmployeeInfo" AttributeDataType="string" AttributeCMValue="" AttributeContolItem="TextBox" />
      <AttributeItem AttributeType="Tele_No" Attributelabel="Business Phone No." AttributeObject="ATLEmployeeInfo" AttributeDataType="string" AttributeCMValue="" AttributeContolItem="TextBox" />
    </AttributeRow>
  </MainRow>
  <MainRow Heading="StockedItemLine">
    <AttributeRow>
      <AttributeItem AttributeType="Margin" Attributelabel="Margin" AttributeObject="ATLEmployeeInfo" AttributeDataType="Double" AttributeCMValue="" AttributeContolItem="TextBox" />
      <AttributeItem AttributeType="MaterialInStock" Attributelabel="Material In Stock?" AttributeObject="ATLEmployeeInfo" AttributeDataType="Boolean" AttributeCMValue="" AttributeContolItem="TextBox" />
    </AttributeRow>
    <AttributeRow>
      <AttributeItem AttributeType="SupplierName" Attributelabel="If No Select Supplier" AttributeObject="ATLEmployeeInfo" AttributeDataType="string" AttributeCMValue="" AttributeContolItem="DropDownList" />
    </AttributeRow>
    <AttributeRow>
      <AttributeItem AttributeType="SupplierContact" Attributelabel="Supplier Contact" AttributeObject="ATLEmployeeInfo" AttributeDataType="string" AttributeCMValue="" AttributeContolItem="CommentTextBox" />
    </AttributeRow>
  </MainRow>
</MainTable>



C#
void lnksubCell_Command(object sender, CommandEventArgs e)
        {
            string strTemp = Convert.ToString(e.CommandArgument);
            string[] strTempArray = Convert.ToString(strTemp).Split(new Char[] { ',' });

            string rowIndex = strTempArray[0].ToString();
            string tableIndex = strTempArray[1].ToString();


            XmlNodeList listMainrow = m_xmld.GetElementsByTagName("MainRow");
            XmlNode listAttRow = listMainrow[Convert.ToInt32(tableIndex)].ChildNodes[Convert.ToInt32(rowIndex)];

            XmlElement newElement = default(XmlElement);
            newElement= m_xmld.CreateElement("AttributeItem");

            XmlAttribute Attr = default(XmlAttribute);
            Attr = m_xmld.CreateAttribute("AttributeType");
            newElement.Attributes.Append(Attr);


            XmlAttribute Attr1 = default(XmlAttribute);
            Attr1 = m_xmld.CreateAttribute("Attributelabel");
            newElement.Attributes.Append(Attr1);


            XmlAttribute Attr2 = default(XmlAttribute);
            Attr2 = m_xmld.CreateAttribute("AttributeObject");
            newElement.Attributes.Append(Attr2);


            XmlAttribute Attr3 = default(XmlAttribute);
            Attr3 = m_xmld.CreateAttribute("AttributeDataType");
            newElement.Attributes.Append(Attr3);


            XmlAttribute Attr4 = default(XmlAttribute);
            Attr4 = m_xmld.CreateAttribute("AttributeCMValue");
            newElement.Attributes.Append(Attr4);


            XmlAttribute Attr5 = default(XmlAttribute);
            Attr5 = m_xmld.CreateAttribute("AttributeContolItem");
            newElement.Attributes.Append(Attr5);

            listAttRow.AppendChild(newElement);
           
            m_xmld.DocumentElement.AppendChild(listAttRow);

            string MainXML = m_xmld.OuterXml;

            //Data base connection and pass string "MainXML" to database .....
}
Posted
Updated 29-May-12 2:54am
v2

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