XmlDocument SO 35676471

CSharp · Console

/Program.cs

using System;
using System.Xml;
using System.Xml.Linq;
using System.Linq;
using System.Collections.Generic;
					
public class Program
{
	public static void Main()
	{
		var xml = @"
<JMF SenderID='InkZone-Controller' Version='1.2' xmlns='http://www.CIP4.org/JDFSchema_1_1'>
    <Command ID='cmd.00695' Type='Resource'>
        <ResourceCmdParams ResourceName='InkZoneProfile' JobID='K_41'>
            <InkZoneProfile ID='r0013' Class='Parameter' Locked='false' Status='Available' PartIDKeys='SignatureName SheetName Side Separation' DescriptiveName='Schieberwerte von DI' ZoneWidth='32'>
                <InkZoneProfile SignatureName='SIG1'>
                    <InkZoneProfile Locked='false' SheetName='S1'>
                        <InkZoneProfile Side='Front'>
                            <InkZoneProfile Separation='designer PG 1901' ZoneSettingsX='0.391 '/>

                        </InkZoneProfile>
                    </InkZoneProfile>
                </InkZoneProfile>
            </InkZoneProfile>
        </ResourceCmdParams>
    </Command>
</JMF>";
		var xmlDoc = new XmlDocument();
		xmlDoc.LoadXml(xml);
		XmlNode root = xmlDoc.DocumentElement;
		XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
		nsmgr.AddNamespace("CIP4NS", "http://www.CIP4.org/JDFSchema_1_1");
		var parent = root.SelectSingleNode("//CIP4NS:Command/CIP4NS:ResourceCmdParams/CIP4NS:InkZoneProfile/CIP4NS:InkZoneProfile/CIP4NS:InkZoneProfile/CIP4NS:InkZoneProfile", nsmgr);

		Console.WriteLine(parent.OuterXml);
	}
}
;