日期:2014-05-18 浏览次数:20353 次
void Page_Load(object sender, EventArgs e) { //Location of XML file string xmlFilePath = Request.PhysicalApplicationPath + @"Employees.xml"; //Create the XmlReaderSettings object and set appropriate properties XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreComments = true; settings.IgnoreWhitespace = true; try { //Get reference to the XmlReader object using (XmlReader reader = XmlReader.Create(xmlFilePath, settings)) { string result; while (reader.Read()) { //Process only the elements if (reader.NodeType == XmlNodeType.Element) { for (int count = 1; count <= reader.Depth; count++) { result += "=> " + reader.Name + "<br/>"; } } } } } catch (Exception ex) { lblResult.Text = "An Exception occurred: " + ex.Message; } }