I am currently studying for the 70-431 exam, and battling with understanding XML
In one of the exercises, they want you to modify a record that looks like this:
<logRecord machine="server2" timestamp="2000-01-11T12:1
3:14Z">
<information flag="failure">
<message>Original message was here</message>
</information>
<error number="18763">
<message>Application can not start</message>
<module>AppLoader</module>
</error>
<post eventType="appStart" />
</logRecord>
To this:
<logRecord machine="server2" timestamp="2000-01-11T12:1
3:14Z">
<information flag="failure">
<message>Not enough memory</message>
</information>
<error number="18763">
<message>Application can not start</message>
<module>AppLoader</module>
</error>
<post eventType="appStart" />
</logRecord>
Not wanting to experiment with the underlying data, I wrote the following script:
declare @x xml
select @x = LogRecord from UniversalLog where ApplicationName = 'HoursReport'
set @x.modify('
replace value of (logRecord/information/mes
sage)[1]
with "Not enough memory"')
select @x
This fails with the following message:
XQuery [modify()]: The target of 'replace value of' must be a non-metadata attribute or an element with simple typed content, found 'element(message,xdt:untyp
ed) ?'
Yet in the completed answer they give the following, which does work:
UPDATE UniversalLog
SET LogRecord.modify('
replace value of (logRecord/information/mes
sage)[1]
with "Not enough memory"')
WHERE ApplicationName = 'HoursReport'
This is the same modify statement, and it works OK.
Why would it not work with my experimental way?
Thanks!
Dabas
Start Free Trial