C# 如何在 xmlnode 中存储网站列表

发布于 2024-08-21 04:03:09 字数 505 浏览 4 评论 0原文

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

  • 站点1

    1. 列表1

      • 文件夹1
      • 文件夹2
        a] 文件1
        b]文件2
      • 文件夹3
    2. 列表2

  • 站点2
    1. 列表1
    2. 列表2
  • 站点3 …………
  • 站点4 ......................

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

I am trying to store website contents in XmlNode.
my website structure is

  • Site1

    1. List1

      • Folder1
      • Folder2

        a] file1

        b] file2
      • Folder3
    2. List2

  • Site2
    1. List1
    2. List2
  • Site3
    ...............
  • Site4
    .........................

So how do i store it in XMLNode. my method should return whole structure as an node not as document.
Thanks in advance.
EDIT: In above case what are the node or element and how to maintain proper hierarchy.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七度光 2024-08-28 04:03:09

如果解析 html 或创建 XMLNod 出现问题,您能更具体一点吗? 的部分

这是一个链接,显示通过代码创建 xml ti 创建 XMLDocument 但您可以仅使用创建根 XMLNode http://www.java2s.com/Code/CSharp/XML/ProgrammaticallycreatinganewXMLdocument.htm

关于解析 html,请查看此链接

寻找 C# HTML 解析器

can you be more specific waht is the problem if the problem parsing the html or creating the XMLNod. Here is A link that shows creating xml by code ti creates XMLDocument but you can use just tha part that creates the root XMLNode

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

About parsing th html look at this link

Looking for C# HTML parser

大姐,你呐 2024-08-28 04:03:09

在我看来,您希望遍历“对象模型”(您的站点结构)并使用此结构构建 XML 文档。

递归函数将是一个选项(伪代码):

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);

希望这有帮助,

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,

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文