Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8841607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:45:42+00:00 2026-06-14T10:45:42+00:00

I’m trying to modify a third party xml so that all the elements have

  • 0

I’m trying to modify a third party xml so that all the elements have Id’s from T-SQL.

This is the original xml (section):

<Tables>
   <Table Type="LineItem">
      <TableRow>
        <Field Name="LI_NominalCode" Type="wd_lit_nominalcode">244234</Field>
        <Field Name="LI_NominalDesc" Type="lit_nominaldesc">RENT RECEIVABLE - INTERNAL</Field>
        <Field Name="LI_Account" Type="lit_wd_account" />
        <Field Name="LI_AccountDesc" Type="lit_wd_accountdesc" />
        <Field Name="LI_SecondAccount" Type="lit_wd_2ndaccount" />
        <Field Name="LI_SecondAccountDesc" Type="lit_wd_2ndaccountdesc" />
        <Field Name="LI_NetValue" Type="lit_vatexcludedamount">4522.89</Field>
        <Field Name="LI_EnergyUsage" Type="wd_energyusage">56666</Field>
        <Field Name="LI_EnergyType" Type="wd_energytype">ELECTRICITY</Field>
      </TableRow>
      <TableRow>
        <Field Name="LI_NominalCode" Type="wd_lit_nominalcode">150021</Field>
        <Field Name="LI_NominalDesc" Type="lit_nominaldesc">Rent Building 1</Field>
        <Field Name="LI_Account" Type="lit_wd_account" />
        <Field Name="LI_AccountDesc" Type="lit_wd_accountdesc" />
        <Field Name="LI_SecondAccount" Type="lit_wd_2ndaccount" />
        <Field Name="LI_SecondAccountDesc" Type="lit_wd_2ndaccountdesc" />
        <Field Name="LI_NetValue" Type="lit_vatexcludedamount">456.37</Field>
        <Field Name="LI_EnergyUsage" Type="wd_energyusage">2805.00</Field>
        <Field Name="LI_EnergyType" Type="wd_energytype">ELECTRICITY</Field>
      </TableRow>
      <TableRow>
        <Field Name="LI_NominalCode" Type="wd_lit_nominalcode">2342341</Field>
        <Field Name="LI_NominalDesc" Type="lit_nominaldesc">Rent Building 2</Field>
        <Field Name="LI_Account" Type="lit_wd_account" />
        <Field Name="LI_AccountDesc" Type="lit_wd_accountdesc" />
        <Field Name="LI_SecondAccount" Type="lit_wd_2ndaccount" />
        <Field Name="LI_SecondAccountDesc" Type="lit_wd_2ndaccountdesc" />
        <Field Name="LI_NetValue" Type="lit_vatexcludedamount">355</Field>
        <Field Name="LI_EnergyUsage" Type="wd_energyusage">6900</Field>
        <Field Name="LI_EnergyType" Type="wd_energytype">ELECTRICITY</Field>
      </TableRow>
    </Table>
    <Table Type="BankAccountTable" />
    <Table Type="VATTable" />
  </Tables>

As you can see, the <Table> elements don’t have Id’s, so later in the process is difficult to identify them.

I’d like to create a loop to go through all the <Table> elements and execute a snippet like this:

set @xml.modify('
insert attribute ID {sql:variable("@idString")}
into (/Documents/Document/Invoice/Tables/Table[@Type="LineItem"]/TableRow)[sql:variable("@id")]')

The problem lies on the last sql variable, the error is:

XQuery [modify()]: Only ‘http://www.w3.org/2001/XMLSchema#decimal?&#8217;,
‘http://www.w3.org/2001/XMLSchema#boolean?&#8217; or ‘node()*’ expressions
allowed as predicates, found ‘xs:string ?’

This works fine, but I dont want to change always the same row (number 1).

set @xml.modify('
insert attribute ID {sql:variable("@idString")}
into (/Documents/Document/Invoice/Tables/Table[@Type="LineItem"]/TableRow)[1]')

By the way, if I use an int variable instead of a string as such:

set @xml.modify('insert attribute ID {sql:variable("@idString")} 
                 into (/Documents/Document/Invoice/Tables/Table[@Type="LineItem"]/TableRow)[sql:variab‌​le("@idInt")]')` 

I get another error:

XQuery [modify()]: The target of ‘insert’ must be a single node, found
‘element(TableRow,xdt:untyped) *

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:45:43+00:00Added an answer on June 14, 2026 at 10:45 am

    You can compare the variable @id to function position().

    declare @id int
    declare @RowCount int
    select @RowCount = @xml.value('count(/Tables/Table[@Type="LineItem"]/TableRow)', 'int')
    
    set @id = 1
    
    while @id <= @RowCount
    begin
      set @xml.modify('
        insert attribute ID {sql:variable("@id")}
        into (/Tables/Table[@Type="LineItem"]/TableRow[position()=sql:variable("@id")])[1]')
    
      set @id = @id + 1
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.