views:

42

answers:

2

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.

A: 

Hi, 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

http://stackoverflow.com/questions/100358/looking-for-c-html-parser

IordanTanev
A: 

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,

Marvin Smit