首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >.selectsinglenode返回null

.selectsinglenode返回null
EN

Stack Overflow用户
提问于 2013-09-25 17:57:24
回答 2查看 2.1K关注 0票数 0

我真的只是在尝试选择

代码语言:javascript
复制
    SOPDetail  
    TargetInfo   
DomesticJurisidiction

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

代码语言:javascript
复制
        /*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来选择它呢?

代码语言:javascript
复制
<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>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-09-25 18:07:08

不要忘记使用Xml名称空间

代码语言:javascript
复制
XmlNamespaceManager nsMgr = new XmlNamespaceManager(xDoc.NameTable);
nsMgr.AddNamespace("x", "http://usop.ctadvantage.com/");
XmlNode targetNode = xDoc.SelectSingleNode("/x:SOPDetail/x:TargetInfo/x:DomesticJurisdiction", nsMgr);
票数 2
EN

Stack Overflow用户

发布于 2013-09-25 17:59:51

你拼错了

代码语言:javascript
复制
   /*XmlNode targetNode = xDoc.SelectSingleNode("/SOPDetail/TargetInfo/DomesticJurisidiction");

DomesticJurisidiction

DomesticJurisdiction

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19011954

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档