skip to main | skip to sidebar
Prabir Kumar Basak's Blog
RSS

Create an XML with attribute

XML 0 comments

protected void CreateXML()
    {
        try
        {
            XmlDocument SettingsXML = new XmlDocument();

            if (File.Exists(Server.MapPath(SettingsXMLPath)))
            {

                SettingsXML.Load(Server.MapPath(SettingsXMLPath));
                XmlNodeList nodeXMLList = SettingsXML.SelectNodes("/UserGroups/Authentication");

                XmlNode node = CreateNode(SettingsXML);
                //Get reference to the book node and append the book node to it
                XmlNode userGroupsNode = SettingsXML.SelectSingleNode("/UserGroups");
                userGroupsNode.AppendChild(node);

            }
            else
            {
                XmlNode declarationNode = SettingsXML.CreateXmlDeclaration("1.0", "utf-8", "");
                SettingsXML.AppendChild(declarationNode);
                XmlNode userGroupsNode = SettingsXML.CreateElement("/UserGroups");
                XmlNode node = CreateNode(SettingsXML);
                userGroupsNode.AppendChild(node);
                SettingsXML.AppendChild(userGroupsNode);
            }

            SettingsXML.Save(Server.MapPath(SettingsXMLPath));
            if (Flag != "True")
            {
                lblMessage.Text = "User Registered Successfully.";
            }
            else
            {
                lblMessage.Text = "UserId already exists.";
            }
           
            txtUserId.Text = "";
            txtPassword.Text = "";
        }
        catch (Exception ex)
        {
            HttpContext.Current.Response.Write(ex.Message);
        }
    }
   
    XmlNode CreateNode(XmlDocument doc)
    {
        XmlNode node = doc.CreateElement("Authentication");
       
        XmlAttribute userIDAttribute = doc.CreateAttribute("UserID");
        userIDAttribute.Value = Guid.NewGuid().ToString();
        node.Attributes.Append(userIDAttribute);

        //Add all the children of the node 
        XmlNode authType = doc.CreateElement("AuthType");
        authType.InnerText = ddlUserType.SelectedValue;
        node.AppendChild(authType);

        XmlNode accessId = doc.CreateElement("AccessId");
        accessId.InnerText = txtUserId.Text;
        node.AppendChild(accessId);

        XmlNode accessKey = doc.CreateElement("AccessKey");
        accessKey.InnerText = txtPassword.Text;
        node.AppendChild(accessKey);

        XmlNode creationDate = doc.CreateElement("CreationDate");
        creationDate.InnerText = DateTime.Now.ToLongDateString();
        node.AppendChild(creationDate);

        return node;
        }


7:34 PM



Newer Posts Older Posts Home
Subscribe to: Comments (Atom)

    Blog Archive

    • ▼  2010 (6)
      • ▼  July (1)
        • Create an XML with attribute
      • ►  March (1)
      • ►  February (3)
      • ►  January (1)

    About Me

    My photo
    Prabir
    Web based application developer, working with Microsoft.Net technology.
    View my complete profile

    Search This Blog

    Labels

    • Blog Archive (1)
    • Image Resizing (1)
    • Search (1)
    • Stored Procedure (3)
    • XML (1)

    Followers

Copyright © All Rights Reserved. Prabir Kumar Basak's Blog | Converted into Blogger Templates by Theme Craft