当你想在你的代码中找到一个错误时,这很难;当你认为你的代码是不会有错误时,这就更难了。

使用C编写XML#

admin 82℃
如何使用c创建具有此格式的xml文件?

<?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>

你可以看看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");

另一种选择是使用XmlWriterXmlDocument

转载请注明:我的代码 » 使用C编写XML#