开发者

XML Based Project File

Looking to alter the way my application saves files. I'd like to have an XML based project file (projectname.blah) which contains references to the two files that are part of each project similar to how Visual Studio does with it's .csproj files.

It should look something like this:

<?xml version="1.0" encoding="utf-8"?>
<Project version="1.0" authorname="user" xmlns="http://www.w3.org/2001/XMLSchema">
      <Platform=".NET"/>
      <Code="codefile.xml"/>
   开发者_JAVA百科   <Canvas="canvas.xml"/>

</Project>

Since I've never done this before, I'm guessing I would be using XmlDocument to create this file when a user does a file new operation. Been looking for examples online but not having any luck. Am I on the right track here?


Your example is not valid XML. Try the following:

public XDocument NewDocument(string path)
{
    var doc =
        new XDocument(
            new XElement(
                "Project",
                new XAttribute("version", "1.0"),
                new XAttribute("authorname", "user"),
                new XElement("Platform", ".NET"),
                new XElement("Code", "codefile.xml"),
                new XElement("Canvas", "canvas.xml")));
    doc.Save(path);
    return doc;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜