Accessing Markup from Nodes

There may be times when you need to access an element's contents in markup form. The XmlNode class provides two properties for retrieving a node's XML markup content: OuterXml and InnerXml. OuterXml returns the content of the current node, with the current node as the root element. The InnerXml property returns only the content of the current element. The XML returned from InnerXml should be considered an XML fragment. Listing 11.10 shows how to use OuterXml and InnerXml to display the markup content of the node.

Listing 11.10.
 C# XmlDocument doc = new XmlDocument(); Doc.LoadXml("<Book>" + "<Title>Catcher in the Rye</Title>" + "<Price>25.98</Price>" + "</Book>"); MessageBox.Show("OuterXml:" + doc.DocumentElement.OuterXml); ...

Get Microsoft® .NET Compact Framework Kick Start now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.