c# Xml解析类和应用
这是面向对象的课程设计作业,就是自己写xml解析类并且完成由xml文件向图形的转化。
这里用了两种方法,第一种是c#自己提供的xml解析函数,第二种是自己的xml解析函数。
xml解析函数(原创)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication1
{
public class xmlParser
{
string s = null;
string temp;
bool isnull = false;
byte[] byteArray = new byte[1];
Stack<TreeNode> nodeStack = new Stack<TreeNode>();
List<string> contents = new List<string>();
bool newline = false;
public TreeNode xmlParse(string addr)
{
TreeNode elemNode = new TreeNode();
FileStream f = new FileStream(addr, FileMode.Open, FileAccess.Read);
while (isnull == false)
{
int i = f.Read(byteArray, 0, 1);
temp =System.Text.Encoding.Default.GetString(byteArray);
if (i < 1)
{
isnull = true;
break;
}
if (temp == null)
&