XML Reader

|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;

namespace XMLReader1
	{
	public partial class Form1 : Form
		{
		public Form1()
			{
			InitializeComponent();
			}

		private void Form1_Load(object sender, EventArgs e)
			{

			string xmlString = "04228911.xml";
			XmlDocument doc = new XmlDocument();
			doc.Load(@xmlString);

			//Create an XmlNamespaceManager for resolving namespaces.
			XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
			nsmgr.AddNamespace("O", "mti_ocrff31_schema.XML");

			//Select the node with the matching attribute value.
			XmlNode CPFField;
			XmlElement root = doc.DocumentElement;
			CPFField = root.SelectSingleNode("descendant::O:Zone[@O:Number='1']", nsmgr);


			OutputTextBlock.Text = CPFField.OuterXml;
			//OutputTextBlock.Text = CPFField.LastChild.InnerText.ToString();

			}
		}
	}

Originally Posted on October 15, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.