[Mono-docs-list] Handbook TOC parser
Johannes Roith
johannes@jroith.de
Thu, 24 Apr 2003 15:11:16 +0200
This is a multi-part message in MIME format.
------=_NextPart_000_0001_01C30A73.C46165A0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Hi!
I have attached a simple parser for the Handbook TOC.
Johannes
------=_NextPart_000_0001_01C30A73.C46165A0
Content-Type: application/octet-stream;
name="simpleparser.cs"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="simpleparser.cs"
// Simple Parser for the Handbook TOC format
// Copyright 2003 by Johannes Roith
using System;
using System.Xml;
public class SimpleHandbookTOCParser
{
public static string spaces = "";
public static void Main()
{
XmlDocument doc = new XmlDocument();
doc.Load("Documentation.xml");
XmlNodeList nodeList = doc.GetElementsByTagName("body");
XmlNodeList bodylist = nodeList[0].ChildNodes[1].ChildNodes;
ParseUl(bodylist[1].ChildNodes);
}
public static void ParseUl(XmlNodeList items)
{
for (int i = 0;i < items.Count;i++)
{
if (items[i].LocalName == "li")
{
string[] attribs = ParseLi(items[i]);
if (items.Count > i+1 && items[i+1].LocalName == "ul")
{
Console.WriteLine(spaces + "+" + attribs[0] + ": " + attribs[1]);
}
else {
Console.WriteLine( spaces + attribs[0] + ": " + attribs[1]);
}
}
if (items[i].LocalName == "ul")
{
spaces += " ";
ParseUl(items[i].ChildNodes);
spaces = spaces.Substring(6);
}
}
}
public static string[] ParseLi(XmlNode me)
{
string[] values = {null, null};
foreach (XmlNode param in me.ChildNodes[0].ChildNodes)
{
if (param.Attributes.GetNamedItem("name").Value == "Name")
values[0] = param.Attributes.GetNamedItem("value").Value;
if (param.Attributes.GetNamedItem("name").Value == "Local")
values[1] = param.Attributes.GetNamedItem("value").Value;
}
return values;
}
}
------=_NextPart_000_0001_01C30A73.C46165A0--