我正在尝试将网站内容存储在 XmlNode 中。我的网站结构是
站点1
清单 1
- 文件夹 1
- 文件夹 2
a] 文件 1
b]文件 2- 文件夹 3
清单2
- 站点2
- 清单 1
- 清单2
- 站点 3 ......
- 站点 4 ....................
那么我如何将它存储在 XMLNode 中。我的方法应该将整个结构作为节点而不是文档返回。
提前致谢。
编辑:在上述情况下,节点或元素是什么以及如何维护适当的层次结构。
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,
如果解析 html 或创建 XMLNod 的问题,你能更具体一点吗?这是一个显示通过代码创建 xml 的链接 ti 创建 XMLDocument 但您可以仅使用创建根 XMLNode 的部分
http://www.java2s.com/Code/CSharp/XML/ProgrammaticallycreatinganewXMLdocument.htm
关于解析 html 看看这个链接