SelectSingleNode returns null 即使有名称空间管理

SelectSingleNode returns null even with namespace managing

我来自这个问题,我的第一个问题已经解决了: 首先是命名空间问题。

但现在即使使用 corect NameSpace 管理我的 XPath 仍然 returns me null。

我也检查过:

SelectSingleNode return null - even with namespace SelectSingleNode always returns null? XmlDocument.SelectSingleNode and xmlNamespace issue SelectSingleNode returning null for known good xml node path using XPath Why is SelectSingleNode returning null?

但是 none 他们帮助了我。我在这个问题上被困了几个小时。这有什么问题吗?

感谢您的帮助。

样本XML(已编辑:完整XML)

<?xml version="1.0" encoding="utf-8"?>
<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 P&G 1901" ZoneSettingsX="0.391 "/>

                        </InkZoneProfile>
                    </InkZoneProfile>
                </InkZoneProfile>
            </InkZoneProfile>
        </ResourceCmdParams>
    </Command>
</JMF>

我选择指定XML节点的代码:

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("C:\XML\test.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/ResourceCmdParams/InkZoneProfile/InkZoneProfile/InkZoneProfile/InkZoneProfile", nsmgr);
XmlElement IZP = xmlDoc.CreateElement("InkZoneProfile");
IZP.SetAttribute("Separation", x.colorname);
IZP.SetAttribute("ZoneSettingsX", x.colorvalues);
parent.AppendChild(IZP);
xmlDoc.Save("C:\XML\test.xml");

您的 XML 具有 默认命名空间 ,没有前缀的后代元素 隐式继承 来自祖先。这意味着,不仅根元素而且 XPath 中提到的所有元素都在同一个默认名称空间中,因此需要使用相同的前缀来引用:

//CIP4NS:Command/CIP4NS:ResourceCmdParams/CIP4NS:InkZoneProfile/CIP4NS:InkZoneProfile/CIP4NS:InkZoneProfile/CIP4NS:InkZoneProfile