如何在c#中包含ExtensionContent中的变量



我有这部分代码用于XML生成,并希望能够从ExtensionContent内部获取和调用变量,例如,在代码中添加变量更改此值OTcwNjljYzUwY2JlZTI4NWRkNDM2NmVhMDM3MGJhM2NjNDZlZTJjMjYxZDkwYzUyM2RiZjYyODNkNmQ4ZTM3OA==

ExtensionContent = @"<sig:UBLDocumentSignatures xmlns:sig=""urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2"" xmlns:sac=""urn:oasis:names:specification:ubl:schema:xsd:SignatureAggregateComponents-2"" xmlns:sbc=""urn:oasis:names:specification:ubl:schema:xsd:SignatureBasicComponents-2"">
<sac:SignatureInformation>                                     
<sbc:ReferencedSignatureID>urn:oasis:names:specification:ubl:signature:Invoice</sbc:ReferencedSignatureID>
<ds:Signature xmlns:ds=""http://www.w3.org/2000/09/xmldsig#"" Id=""signature"">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm=""http://www.w3.org/2006/12/xml-c14n11""/>
<ds:SignatureMethod Algorithm=""http://www.w3.org/2001/04/xmldsig-more#rsa-sha256""/>
<ds:Reference Id=""invoiceSignedData"" URI="""">
<ds:Transforms>
<ds:Transform Algorithm=""http://www.w3.org/TR/1999/REC-xpath-19991116"">
<ds:XPath>not(//ancestor-or-self::ext:UBLExtensions)</ds:XPath>
</ds:Transform>
<ds:Transform Algorithm=""http://www.w3.org/TR/1999/REC-xpath-19991116"">
<ds:XPath>not(//ancestor-or-self::cac:Signature)</ds:XPath>
</ds:Transform>
<ds:Transform Algorithm=""http://www.w3.org/TR/1999/REC-xpath-19991116"">
<ds:XPath>not(//ancestor-or-self::cac:AdditionalDocumentReference[cbc:ID='QR'])</ds:XPath>
</ds:Transform>
<ds:Transform Algorithm=""http://www.w3.org/2006/12/xml-c14n11""/>
</ds:Transforms>
<ds:DigestMethod Algorithm=""http://www.w3.org/2001/04/xmlenc#sha256""/>
<ds:DigestValue>lYQcYGXl6hCf+ZZPNdr1wajasZBRGKXlNepHUG+S4HA=</ds:DigestValue>
</ds:Reference>
<ds:Reference Type=""http://www.w3.org/2000/09/xmldsig#SignatureProperties"" URI=""#xadesSignedProperties"">
<ds:DigestMethod Algorithm=""http://www.w3.org/2001/04/xmlenc#sha256""/>
<ds:DigestValue>OTcwNjljYzUwY2JlZTI4NWRkNDM2NmVhMDM3MGJhM2NjNDZlZTJjMjYxZDkwYzUyM2RiZjYyODNkNmQ4ZTM3OA==</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue></ds:SignatureValue>
<ds:KeyInfo>
<ds:X509Data>
<ds:X509Certificate>MIIB5zCCAY6gAwIBAgIGAX4+qePlMAoGCCqGSM49BAMCMBUxEzARBgNVBAMMCmVJbnZvaWNpbmcwHhcNMjIwMTA5MTE0NzAzWhcNMjcwMTA4MjIwMDAwWjBIMQswCQYDVQQGEwJTQTEVMBMGA1UECwwMUnlpYWQgQnJhbmNoMQ4wDAYDVQQKDAVKZXJpcjESMBAGA1UEAwwJMTI3LjAuMC4xMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEprhOfBA8ACO+nTVY7k8f7Kt4aJ0Utb55LUPLmnVUsvYp9/gOH22ix2NoKObrQKw/QI5N1wa3g3a1/ynpUJ8CfKOBmTCBljAMBgNVHRMBAf8EAjAAMIGFBgNVHREEfjB8pHoweDEYMBYGA1UEBAwPMzU0MzU0MzU4ODM0MzI1MR8wHQYKCZImiZPyLGQBAQwPMzEwMTIyMzkzNTAwMDAzMQ0wCwYDVQQMDAQxMDAwMREwDwYDVQQaDAhTYW1wbGUgRTEZMBcGA1UEDwwQU2FtcGxlIEJ1c3NpbmVzczAKBggqhkjOPQQDAgNHADBEAiAJZL0+rr5v9cw5/KOVi1c/5FDvIWg4XQ0d711fQQ5XNAIgTihCpVdM7pSG0kawh7P5PmxkupTWx9ilaDz0G/56IEU=</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
<ds:Object>
<xades:QualifyingProperties xmlns:xades=""http://uri.etsi.org/01903/v1.3.2#"" Target=""signature"">
<xades:SignedProperties Id=""xadesSignedProperties"">
<xades:SignedSignatureProperties>
<xades:SigningTime>2022-03-31T12:13:18Z</xades:SigningTime>
<xades:SigningCertificate>
  <xades:Cert>
      <xades:CertDigest>
          <ds:DigestMethod Algorithm=""http://www.w3.org/2001/04/xmlenc#sha256""/>
          <ds:DigestValue>ZGNjZTk3MGIzYjg0M2FlODczNGIyMDQ3ZjczOTM2NjgyNjljYmQ4NGYyZThkOTlmY2ZjYTU0ODFhZWE3MjE4NA==</ds:DigestValue>
      </xades:CertDigest>
      <xades:IssuerSerial>
          <ds:X509IssuerName>CN=eInvoicing</ds:X509IssuerName>
          <ds:X509SerialNumber>1641728828389</ds:X509SerialNumber>
      </xades:IssuerSerial>
  </xades:Cert>
</xades:SigningCertificate>
</xades:SignedSignatureProperties>
</xades:SignedProperties>
</xades:QualifyingProperties>
</ds:Object>
</ds:Signature>
</sac:SignatureInformation>
</sig:UBLDocumentSignatures>".ToXmlElement()
}
},

在。net框架工具中有一个叫做xsd.exe的工具

它允许您创建一个或多个与XML匹配的c#类。然后,您可以使用XML序列化器将XML反序列化为。net对象,更新属性,然后将对象序列化回XML并保存。

这是一篇来自微软的文章,包含了关于xsd.exe的更多信息

https://learn.microsoft.com/en-us/dotnet/standard/serialization/xml-schema-def-tool-gen

相关内容

  • 没有找到相关文章