-1

我正在尝试将网站内容存储在 XmlNode 中。我的网站结构是

  • 站点1

    1. 清单 1

      • 文件夹 1
      • 文件夹 2
        a] 文件 1
        b]文件 2
      • 文件夹 3
    2. 清单2

  • 站点2
    1. 清单 1
    2. 清单2
  • 站点 3 ......
  • 站点 4 ....................

那么我如何将它存储在 XMLNode 中。我的方法应该将整个结构作为节点而不是文档返回。 提前致谢。
编辑:在上述情况下,节点或元素是什么以及如何维护适当的层次结构。

4

2 回答 2

0

Sounds to me you would like to waLk the ´object model´ (your site structure) and build an XML document with this structure.

A recursive function would be an option (pseudo code):

BuildRecursiveStructure(SiteStructureNode currentSiteNode, XmlNode buildNode)
{
        newNode = xDoc.CreateElement( currentSiteNode.name );
    buildNode.addChild( newNode );
        foreach (?? childSiteNode in currentSiteNode.Children)
    {
        BuildRecursiveStructure( childSiteNode, newNode );
    }
}

XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml("");

BuildRecursiveStrucure( SitesInfoRoot? , xDoc.DocumentElement);

Hope this helps,

于 2010-02-13T13:02:10.440 回答
0

如果解析 html 或创建 XMLNod 的问题,你能更具体一点吗?这是一个显示通过代码创建 xml 的链接 ti 创建 XMLDocument 但您可以仅使用创建根 XMLNode 的部分

http://www.java2s.com/Code/CSharp/XML/ProgrammaticallycreatinganewXMLdocument.htm

关于解析 html 看看这个链接

寻找 C# HTML 解析器

于 2010-02-13T07:49:44.997 回答