如何通过 SQL 或 C# 在 XML 中添加 sepa header
How to add sepa header this in XML via SQL or C#
如何通过 SQL
或 C#
在 XML
中像这样添加 sepa header
。请帮忙
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.008.001.02" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance">
将 WITH XMLNAMESPACES
添加到您的查询中,这将设置默认的 xml 命名空间。
WITH XMLNAMESPACES (
DEFAULT 'urn:iso:std:iso:20022:tech:xsd:pain.008.001.02'
)
您的查询如下所示。
用您的查询更改下面的 SELECT。
WITH XMLNAMESPACES (
DEFAULT 'urn:iso:std:iso:20022:tech:xsd:pain.008.001.02'
)
SELECT * FROM YOUR_TABLE
FOR XML AUTO, ROOT('Document'), ELEMENTS XSINIL
这将导致
<Document
xmlns="urn:iso:std:iso:20022:tech:xsd:pain.008.001.02"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
我已经放弃尝试使用 Net 库来获得正确的命名空间。我只是解析始终有效且更简单的字符串。请参阅下面的代码:
string ident = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Document xmlns:xsi=\"http://www.w3.org/2001/XMLSchemainstance\" xmlns=\"urn:iso:std:iso:20022:tech:xsd:pain.008.001.02\"></Document>";
XDocument doc = XDocument.Parse(ident);
XElement document = doc.Root;
如何通过 SQL
或 C#
在 XML
中像这样添加 sepa header
。请帮忙
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.008.001.02" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance">
将 WITH XMLNAMESPACES
添加到您的查询中,这将设置默认的 xml 命名空间。
WITH XMLNAMESPACES (
DEFAULT 'urn:iso:std:iso:20022:tech:xsd:pain.008.001.02'
)
您的查询如下所示。
用您的查询更改下面的 SELECT。
WITH XMLNAMESPACES (
DEFAULT 'urn:iso:std:iso:20022:tech:xsd:pain.008.001.02'
)
SELECT * FROM YOUR_TABLE
FOR XML AUTO, ROOT('Document'), ELEMENTS XSINIL
这将导致
<Document
xmlns="urn:iso:std:iso:20022:tech:xsd:pain.008.001.02"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
我已经放弃尝试使用 Net 库来获得正确的命名空间。我只是解析始终有效且更简单的字符串。请参阅下面的代码:
string ident = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Document xmlns:xsi=\"http://www.w3.org/2001/XMLSchemainstance\" xmlns=\"urn:iso:std:iso:20022:tech:xsd:pain.008.001.02\"></Document>";
XDocument doc = XDocument.Parse(ident);
XElement document = doc.Root;