我有一个从文件加载的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>
我尝试按属性值 wsu:Id
找到元素 SOAP-ENV:BodyC#
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;
}
但该函数返回null
。
idValue == "body"
我已经在调试模式下检查了它。
如果我尝试按名称document.SelectSingleNode("//SOAP-ENV:Body", nsmgr)
找到元素,它可以工作,但我需要按属性值获取元素。