Solved

XML: replace value of - why is not working

Posted on 2011-03-09
4
441 Views
Last Modified: 2012-05-11
i have this xml
<InvoiceList xmlns="http://schemas.adventure-works.com/Invoices">
  <Invoice InvoiceNo="1000">
    <Customer>Kim Abercrombie</Customer>
    <Items>
      <Item Product="1" Price="1.99" Quantity="2" />
      <Item Product="3" Price="2.49" Quantity="1" />
    </Items>
  </Invoice>
  <Invoice InvoiceNo="1001">
    <Customer>Sean Chai</Customer>
    <Items>
      <Item Product="1" Price="2.45" Quantity="2" />
    </Items>
  </Invoice>
</InvoiceList>

why is not working
UPDATE #Stores
SET Invoices.modify('declare default element namespace "http://schemas.adventure-works.com/Invoices";
  replace value of (/InvoiceList/Invoice/Items[@Price="1.99"]/@Price)[1]
  with "1.69"')
WHERE StoreID = 1
0
Comment
Question by:enrique_aeo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 3

Expert Comment

by:CarlsbergFTW
ID: 35080794
There isn't any 'StoreID' value in the xml you posted tho your query is using it to define specific data.
0
 

Author Comment

by:enrique_aeo
ID: 35080868
it is exits
XML-storeID.jpg
0
 
LVL 6

Accepted Solution

by:
jonaska earned 400 total points
ID: 35082987
Your xpath is incomplete as I see it.
Should be:
UPDATE #Stores
SET Invoices.modify('declare default element namespace "http://schemas.adventure-works.com/Invoices";
  replace value of (/InvoiceList/Invoice/Items/Item[@Price="1.99"]/@Price)[1]
  with "1.69"')
WHERE StoreID = 1
0
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 100 total points
ID: 35083214
The solution offered is absolutely correct, however just a word of caution, doing this type of replacement is risky at best.  If there are two values with price 1.99 in the same node (see below), then only the first will be replaced.
<InvoiceList xmlns="http://schemas.adventure-works.com/Invoices">
  <Invoice InvoiceNo="1000">
    <Customer>Kim Abercrombie</Customer>
    <Items>
      <Item Product="1" Price="1.99" Quantity="2" />
      <Item Product="3" Price="1.99" Quantity="1" />
    </Items>
  </Invoice>
  <Invoice InvoiceNo="1001">
    <Customer>Sean Chai</Customer>
    <Items>
      <Item Product="1" Price="2.45" Quantity="2" />
    </Items>
  </Invoice>
</InvoiceList>

Open in new window

0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question