I'm experimenting with creating PIDX XML data straight from SQL (Microsoft SQL Server 2005 - 9.00.5057.00). I'm just getting started but ran into a roadblock when trying to add an attribute to the root element. This is what I've got so far:
It generates this:
How would I go about adding these attributes to the root (Invoice) element?:
[ul]
[li]pidx:transactionPurposeIndicator="Original"[/li]
[li]pidx:version="1.61"[/li]
[/ul]
It should look like this:
Code:
DECLARE
@xmlDoc VARCHAR(MAX)
,@declaration VARCHAR(MAX)
,@Invoice VARCHAR(MAX)
,@InvoiceProperties VARCHAR(MAX)
,@InvoiceDetails VARCHAR(MAX)
,@InvoiceSummary VARCHAR(MAX)
,@inv_num VARCHAR(12)
,@inv_date VARCHAR(10)
,@invoiceTotal DECIMAL(21,6)
SELECT
@inv_num = LTRIM(RTRIM(inv_num))
,@inv_date = CONVERT(VARCHAR(10),inv_date,126)
,@invoiceTotal = price
FROM inv_hdr
WHERE
inv_num = ' 1445171'
SELECT
@declaration = '<?xml version="1.0" encoding="UTF-8"?>'
;WITH XMLNAMESPACES ('[URL unfurl="true"]http://www.pidx.org/schemas/v1.61'[/URL] as pidx)
SELECT @xmlDoc =
(SELECT @declaration + CAST
(
(
SELECT
@InvoiceProperties AS [pidx:InvoiceProperties]
,@inv_num AS [pidx:InvoiceProperties/pidx:InvoiceNumber]
,@inv_date AS [pidx:InvoiceProperties/pidx:InvoiceDate]
,'test' AS [pidx:InvoiceDetails/@testAttribute]
,@InvoiceDetails AS [pidx:InvoiceDetails]
,@InvoiceSummary AS [pidx:InvoiceSummary]
,@invoiceTotal AS [pidx:InvoiceSummary/pidx:InvoiceTotal]
FOR XML PATH (''), ROOT ('pidx:Invoice')
)
AS VARCHAR(MAX)
)
)
SELECT @xmlDoc
It generates this:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<pidx:Invoice xmlns:pidx="[URL unfurl="true"]http://www.pidx.org/schemas/v1.61">[/URL]
<pidx:InvoiceProperties>
<pidx:InvoiceNumber>1445171</pidx:InvoiceNumber>
<pidx:InvoiceDate>2018-02-08</pidx:InvoiceDate>
</pidx:InvoiceProperties>
<pidx:InvoiceDetails testAttribute="test"/>
<pidx:InvoiceSummary>
<pidx:InvoiceTotal>9913.730000</pidx:InvoiceTotal>
</pidx:InvoiceSummary>
</pidx:Invoice>
How would I go about adding these attributes to the root (Invoice) element?:
[ul]
[li]pidx:transactionPurposeIndicator="Original"[/li]
[li]pidx:version="1.61"[/li]
[/ul]
It should look like this:
Code:
...
<pidx:Invoice xmlns:pidx="[URL unfurl="true"]http://www.pidx.org/schemas/v1.61"[/URL] [highlight]pidx:transactionPurposeIndicator="Original"[/highlight] [highlight]pidx:version="1.61"[/highlight]>
...