So here is the finished product I am looking for:
<GPAutoActions>
<createDispute>
<transaction>
<defaultKey>
<custNo>10000000-AD</custNo>
<invNo>28893848</invNo>
</defaultKey>
</transaction>
<reason>405</reason>
<amount>185.17</amount>
<pnote>Notes</pnote>
<owner>LARRYGIST</owner>
</createDispute>
</GPAutoActions>
Here is the table Structure
custno invno reason amount pnote owner
117455521-AD 28894882 405 972.04 Note LARRYGIST
128623268-AD 28887277 405 182.99 Note LARRYGIST
131537715-AD 28893848 405 185.17 Note LARRYGIST
189063783-AD 28927273 405 777.49 Note LARRYGIST
Here is the SQL I am using:
Select 1 as TAG
, null as parent
, null as 'createDispute!1!'
, null as 'transaction!2!Element'
, null as 'defaultKey!3!'
, null as 'defaultKey!3!custno!Element'
, null as 'defaultKey!3!InvNo!Element'
, null as 'reason!4!'
UNION ALL
Select 2 as Tag
, 1 as Parent
, Null
, NULL
, null
, null
, null
, null
Union ALL
Select 3 as Tag
, 2 as Parent
, Null
, NULL
, null
, custno
, InvNo
, null
FROM [GetPaid_Sandbox].[dbo].[DisputeData]
Union ALL
Select 4 as Tag
, 2 as Parent
, Null
, NULL
, null
, null
, null
, reason
FROM [GetPaid_Sandbox].[dbo].[DisputeData]
for XML EXPLICIT
Here is what is being returned:
<createDispute>
<transaction>
<defaultKey>
<custno>117455521-AD</custno>
<InvNo>28894882</InvNo>
</defaultKey>
<defaultKey>
<custno>128623268-AD</custno>
<InvNo>28887277</InvNo>
</defaultKey>
<defaultKey>
<custno>131537715-AD</custno>
<InvNo>28893848</InvNo>
</defaultKey>
<defaultKey>
<custno>189063783-AD</custno>
<InvNo>28927273</InvNo>
</defaultKey>
<reason>405</reason>
<reason>405</reason>
<reason>405</reason>
<reason>405</reason>
</transaction>
</createDispute>
What I do not understand is why the <transaction> tag is not closing after each <defaultKey> tag? I also will need to add the remainder of the tags after reason code, but I am stuck right here. Should I be using Explicit or will PATH work better in this situation? I hate having to do this from SQL but I am not sure how else to get it done easily.