繁体   English   中英

Xmldoc .selectsinglenode返回null

[英]Xmldoc .selectsinglenode returns null

我真的只是想选择在列出的值

    SOPDetail  
    TargetInfo   
DomesticJurisidiction

每个都是另一个的子节点。 当我进行迭代时,我找到了节点DomesticJurisidiction,但是当我选择使用xpath时,我找不到它。 有人对为什么有建议吗?

        /*XmlNode targetNode = xDoc.SelectSingleNode("/SOPDetail/TargetInfo/DomesticJurisidiction");
        string haha = targetNode.InnerXml;*/

        foreach (XmlNode xmlNode in xDoc.ChildNodes)
        {
            Console.WriteLine(xmlNode.Name);
            foreach (XmlNode chldNode in xmlNode.ChildNodes)
            {
                Console.WriteLine(chldNode.Name);
                foreach (XmlNode cNode in chldNode.ChildNodes)
                {
                    Console.WriteLine(cNode.Name + ":" + cNode.InnerXml);
                }
            }
        }

就像我提到的foreach迭代可以完美地找到此节点,为什么不能使用SelectsingleNode选择它呢?

<SOPDetail LogId="324" LastModified="2007-05-20T09:20:50" xmlns="http://usop.ctadvantage.com/">
  <TargetInfo>
    <DomesticJurisdiction>Connecticut</DomesticJurisdiction>
    <ServedName>CT Demo Account (All State Corp)</ServedName>
    <ServedJurisdiction>New York</ServedJurisdiction>
    <NameDiscrepancyExists>false</NameDiscrepancyExists>
    <Defendant>Test</Defendant>
  </TargetInfo>
  <LawsuitInfo>
    <ReceiptDate>2007-05-20</ReceiptDate>
    <CreatedDate>2007-05-20T08:41:38</CreatedDate>
    <MethodOfService>Courier</MethodOfService>
    <LawsuitType>Other</LawsuitType>
    <LawsuitSubType>Documents requiring hard copy delivery</LawsuitSubType>
    <AnswerDate />
    <DocumentServed>Acknowledgment of Service</DocumentServed>
    <NatureOfAction>
      Notifying of Dft. 's No Opposition Summary Judgment Motion and Order
    </NatureOfAction>
  </LawsuitInfo>
  <CaseType>Standard</CaseType>
  <Remark />
  <CourtInfo>
    <Name />
    <AddressLine1 />
    <AddressLine2 />
    <AddressLine3 />
    <AddressLine4 />
    <City />
    <County />
    <State />
    <Zip />
    <Country />
    <Phone />
    <Fax />
    <Email />
  </CourtInfo>
  <AttorneyInfo>
    <Name />
    <AddressLine1 />
    <AddressLine2 />
    <AddressLine3 />
    <AddressLine4 />
    <City />
    <County />
    <State />
    <Zip />
    <Country />
    <Phone />
    <Fax />
    <Email />
    <LawFirmName />
  </AttorneyInfo>
  <AgencyInfo>
    <Name />
    <AddressLine1 />
    <AddressLine2 />
    <AddressLine3 />
    <AddressLine4 />
    <City />
    <County />
    <State />
    <Zip />
    <Country />
    <Phone />
    <Fax />
    <Email />
  </AgencyInfo>
  <CaseInfo>
    <CaseNumber />
    <Plaintiff />
  </CaseInfo>
  <DocId>123asdf234</DocId>
</SOPDetail>

不要忘记使用Xml命名空间

XmlNamespaceManager nsMgr = new XmlNamespaceManager(xDoc.NameTable);
nsMgr.AddNamespace("x", "http://usop.ctadvantage.com/");
XmlNode targetNode = xDoc.SelectSingleNode("/x:SOPDetail/x:TargetInfo/x:DomesticJurisdiction", nsMgr);

您拼写错误:

   /*XmlNode targetNode = xDoc.SelectSingleNode("/SOPDetail/TargetInfo/DomesticJurisidiction");

国内管辖权

国内管辖权

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM