Добавление пространств имен XML в преобразования XPathC#

Место общения программистов C#
Anonymous
Добавление пространств имен XML в преобразования XPath

Сообщение Anonymous »

Я пытаюсь подписать файл Xml с помощью вызовов SignedXml в .Net 8. У меня возникла проблема с преобразованиями XPath.
Вызов SignedXml.ComputeSignature() выдает ошибку следующее исключение:

Код: Выделить всё

Unhandled exception. System.Xml.XPath.XPathException: Namespace prefix 'ext' is not defined.
at MS.Internal.Xml.XPath.CompiledXpathExpr.UndefinedXsltContext.LookupNamespace(String prefix)
at MS.Internal.Xml.XPath.BaseAxisQuery.SetXsltContext(XsltContext context)
at MS.Internal.Xml.XPath.CompiledXpathExpr.SetContext(IXmlNamespaceResolver nsResolver)
at System.Security.Cryptography.Xml.XmlDsigXPathTransform.GetOutput()
at System.Security.Cryptography.Xml.TransformChain.TransformToOctetStream(Object inputObject, XmlResolver resolver, String baseUri)
at System.Security.Cryptography.Xml.Reference.CalculateHashValue(XmlDocument document, CanonicalXmlNodeList refList)
at System.Security.Cryptography.Xml.Reference.UpdateHashValue(XmlDocument document, CanonicalXmlNodeList refList)
at System.Security.Cryptography.Xml.SignedXml.BuildDigestedReferences()
at System.Security.Cryptography.Xml.SignedXml.ComputeSignature()
Преобразования XPath выглядят следующим образом:

Код: Выделить всё




urn:oasis:names:specification:ubl:dsig:enveloped:xades



urn:oasis:names:specification:ubl:signature:1
urn:oasis:names:specification:ubl:signature:Invoice







not(//ancestor-or-self::ext:UBLExtensions)


not(//ancestor-or-self::cac:Signature)


not(//ancestor-or-self::cac:AdditionalDocumentReference[cbc:ID='QR'])




f+0WCqnPkInI+eL9G3LAry12fTPf+toC9UX07F4fI+s=

Я думал, что этот класс будет достаточно умен, чтобы автоматически получать пространства имен, указанные в выражениях XPath, но, похоже, нет. Как добавить пространства имен, чтобы преобразования XPath работали правильно?

Подробнее здесь: https://stackoverflow.com/questions/788 ... transforms

Вернуться в «C#»