Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# XPath查询未按属性值查找元素_C#_Xpath - Fatal编程技术网

C# XPath查询未按属性值查找元素

C# XPath查询未按属性值查找元素,c#,xpath,C#,Xpath,我有一个从文件加载的XML文档 XML <SOAP-ENV:Envelope xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:SOAP-ENV="ht

我有一个从文件加载的XML文档

XML

<SOAP-ENV:Envelope xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Header>
    <wsse:Security SOAP-ENV:actor="http://smev.gosuslugi.ru/actors/smev">
      <wsse:BinarySecurityToken EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" wsu:Id="BodyCertificate"></wsse:BinarySecurityToken>
      <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
        <SignedInfo>
          <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
          <SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#gostr34102001-gostr3411" />
          <Reference URI="#body">
            <Transforms>
              <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
            </Transforms>
            <DigestMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#gostr3411" />
            <DigestValue></DigestValue>
          </Reference>
        </SignedInfo>
        <SignatureValue></SignatureValue>
        <KeyInfo>
          <wsse:SecurityTokenReference>
            <wsse:Reference URI="#BodyCertificate" />
          </wsse:SecurityTokenReference>
        </KeyInfo>
      </Signature>
    </wsse:Security>
  </SOAP-ENV:Header>
  <SOAP-ENV:Body wsu:Id="body">
    <n1:UnifoTransferMsg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://roskazna.ru/SmevUnifoService/MethodMsg.xsd" xmlns:pirq="http://roskazna.ru/xsd/PGU_ImportRequest" xmlns:smev="http://smev.gosuslugi.ru/rev111111" xmlns:unifo="http://rosrazna.ru/xsd/SmevUnifoService" xmlns:n1="http://roskazna.ru/SmevUnifoService/">
      <smev:Message>
        <smev:Sender>
          <smev:Code></smev:Code>
          <smev:Name></smev:Name>
        </smev:Sender>
        <smev:Recipient>
          <smev:Code></smev:Code>
          <smev:Name></smev:Name>
        </smev:Recipient>
        <smev:Originator>
          <smev:Code></smev:Code>
          <smev:Name></smev:Name>
        </smev:Originator>
        <smev:TypeCode></smev:TypeCode>
        <smev:Status></smev:Status>
        <smev:Date></smev:Date>
        <smev:ExchangeType></smev:ExchangeType>
      </smev:Message>
      <smev:MessageData>
        <smev:AppData>
          <unifo:ImportData>
            <pirq:ImportRequest>
              <PostBlock>
                <ID></ID>
                <TimeStamp></TimeStamp>
                <SenderIdentifier>000164</SenderIdentifier>
              </PostBlock>
              <FinalPayment>
                <SupplierBillID></SupplierBillID>
                <Narrative></Narrative>
                <Amount></Amount>
                <PaymentDate></PaymentDate>
                <BudgetIndex>
                  <Status>0</Status>
                  <PaymentType>0</PaymentType>
                  <Purpose>0</Purpose>
                  <TaxPeriod>0</TaxPeriod>
                  <TaxDocNumber>0</TaxDocNumber>
                  <TaxDocDate>0</TaxDocDate>
                </BudgetIndex>
                <PaymentIdentificationData>
                  <Bank>
                    <Name></Name>
                    <BIK></BIK>
                  </Bank>
                  <SystemIdentifier></SystemIdentifier>
                </PaymentIdentificationData>
                <PayerIdentifier></PayerIdentifier>
                <PayeeBankAcc>
                  <Account></Account>
                  <Bank>
                    <Name></Name>
                    <BIK></BIK>
                  </Bank>
                </PayeeBankAcc>
                <ChangeStatus>1</ChangeStatus>
                <payeeINN></payeeINN>
                <payeeKPP></payeeKPP>
                <KBK></KBK>
                <OKATO></OKATO>
              </FinalPayment>
            </pirq:ImportRequest>
          </unifo:ImportData>
        </smev:AppData>
      </smev:MessageData>
    </n1:UnifoTransferMsg>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
但是函数返回
null

idValue==“body”
我已经在调试模式下检查了它


如果我尝试按名称
文档查找元素。选择SingleNode(“//SOAP-ENV:Body”,nsmgr)
它可以工作,但我需要按属性值获取元素。

您混合了WSSE命名空间URI和WSU命名空间URI。更改分配WSU前缀时添加到XmlNamespaceManager的命名空间uri。谢谢,这很有帮助。我注意力不集中。wsu realy具有wsse以外的其他URI
public override XmlElement GetIdElement(XmlDocument document, string idValue)
{
  XmlNamespaceManager nsmgr = new XmlNamespaceManager(document.NameTable);
  nsmgr.AddNamespace("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
  return document.SelectSingleNode("//*[@wsu:Id='" + idValue + "']", nsmgr) as XmlElement;
}