tags:

views:

59

answers:

1

Hi. How can I create xml file with this format using c#?

<?xml version="1.0" encoding="utf-8" ?>
<wrap>
  <content>
    <title>
      WHAT ARE ROLES?
    </title>
    <text>
        Roles are security based permissions that can be assigned to registered user of the site. Users can have any number of role based security permissions that the administrator deems appropriate. Certain parts of the application may have security permissions assigned to them to make the information they contain available only to those users with the required permisions.
    </text>
  </content>
  <content>
    <title>
      CREATE A ROLE
    </title>
    <text>
        To create a new role, simply enter its name into the textbox on top and click the "Add Role" button. Once it is created, it is then available to the administrator to be used and assigned to any registered user account.
    </text>
  </content>
  <content>
    <title>
      DELETE A ROLE
    </title>
    <text>
        To delete a role, select the checkboxes on the left side of the gridview and click the "Delete Selected" button.
    </text>
  </content>
</wrap>
+5  A: 

You may take a look at XDocument.

XDocument doc = new XDocument(
    new XDeclaration("1.0", "utf-8", "yes"),
    new XElement("wrap",
        new XElement("content",
            new XElement("title", "WHAT ARE ROLES?"),
            new XElement("text", "Roles are security based permissions that can be assigned to registered user of the site. Users can have any number of role based security permissions that the administrator deems appropriate. Certain parts of the application may have security permissions assigned to them to make the information they contain available only to those users with the required permisions")
        ) // continue with other content tags
    ) 
);
doc.Save("test.xml");

Another alternative is to use a XmlWriter or XmlDocument.

Darin Dimitrov
Thank you Darin :).I got the answer.
shaahin
@Darin.For Example My Xml File exist.can i update my file with these codes?i want to open an existing file and update it.
shaahin
Darin Dimitrov
@Darin. Thanks. after that I will Google my problems :)
shaahin