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(); } } }
Last Updated on October 26, 2015