XmlDocument doc = new XmlDocument(); doc.Load("path/to/xml/file.xml"); XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("ns", "http://example.com/ns"); XmlNode childNode = doc.DocumentElement.SelectSingleNode("/ns:ParentElement/ns:ChildElement", nsmgr); if (childNode != null) { // Do something with the child node }
XmlReader reader = XmlReader.Create("path/to/xml/file.xml"); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "ChildElement") { reader.ReadToDescendant("SubChildElement"); // Do something with the SubChildElement node } }In this example, we use the `ReadToDescendant` method to move the cursor to the `SubChildElement` node of the current `ChildElement` node. This helps to parse complex XML documents where we need to navigate through multiple levels of elements. The `ReadToDescendant` method belongs to the System.Xml namespace in C#.