 |
|
 |
|
Next: Retreiving Namespace URI
|
| Author |
Message |
External

Since: Sep 14, 2004 Posts: 13
|
(Msg. 1) Posted: Wed May 21, 2008 8:35 am
Post subject: xml update Archived from groups: microsoft>public>sqlserver>xml (more info?)
|
|
|
I have id and xml columns in mytable. I want to update an element called
myelement with the following
UPDATE MyTable SET
xml.modify
('replace value of
(/root/child/grandchild/myelement)[1] with
xs:dateTime("2002-05-30T09:30:10Z")')
WHERE id = '00000000-0000-0000-0000-000000000000'
But I got
XQuery [mytable.xml.modify()]: The target of 'replace value of' must be a
non-metadata attribute or an element with simple typed content, found
'element(myelement,xdt:untyped) ?'
If I removed "[1]" in the query, I got
XQuery [mytable.xml.modify()]: The target of 'replace' must be at most one
node, found 'element(myelement,xdt:untyped) *'
I am sure it has only one instance of the element in the xml with the given
id.
What is the problem? >> Stay informed about: xml update |
|
| Back to top |
|
 |  |
External

Since: Jan 19, 2008 Posts: 38
|
(Msg. 2) Posted: Wed May 21, 2008 4:26 pm
Post subject: Re: xml update [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Is the XML column typed?
--
Joe Fawcett (MVP - XML)
http://joe.fawcett.name
"Roy" wrote in message
>I have id and xml columns in mytable. I want to update an element called
> myelement with the following
>
> UPDATE MyTable SET
> xml.modify
> ('replace value of
> (/root/child/grandchild/myelement)[1] with
> xs:dateTime("2002-05-30T09:30:10Z")')
> WHERE id = '00000000-0000-0000-0000-000000000000'
>
> But I got
> XQuery [mytable.xml.modify()]: The target of 'replace value of' must be a
> non-metadata attribute or an element with simple typed content, found
> 'element(myelement,xdt:untyped) ?'
>
> If I removed "[1]" in the query, I got
> XQuery [mytable.xml.modify()]: The target of 'replace' must be at most one
> node, found 'element(myelement,xdt:untyped) *'
>
> I am sure it has only one instance of the element in the xml with the
> given
> id.
>
> What is the problem? >> Stay informed about: xml update |
|
| Back to top |
|
 |  |
External

Since: Apr 20, 2007 Posts: 48
|
(Msg. 3) Posted: Wed May 21, 2008 4:26 pm
Post subject: Re: xml update [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Roy wrote:
> I have id and xml columns in mytable. I want to update an element called
> myelement with the following
>
> UPDATE MyTable SET
> xml.modify
> ('replace value of
> (/root/child/grandchild/myelement)[1] with
> xs:dateTime("2002-05-30T09:30:10Z")')
> WHERE id = '00000000-0000-0000-0000-000000000000'
>
> But I got
> XQuery [mytable.xml.modify()]: The target of 'replace value of' must be a
> non-metadata attribute or an element with simple typed content, found
> 'element(myelement,xdt:untyped) ?'
How does the current content of that 'myelement' look, does it contain
child elements?
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/ >> Stay informed about: xml update |
|
| Back to top |
|
 |  |
External

Since: Sep 14, 2004 Posts: 13
|
(Msg. 4) Posted: Wed May 21, 2008 4:26 pm
Post subject: Re: xml update [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
I don't have xsd associated with the column.
"Joe Fawcett" wrote:
> Is the XML column typed?
>
> --
>
> Joe Fawcett (MVP - XML)
>
> http://joe.fawcett.name
>
> "Roy" wrote in message
>
> >I have id and xml columns in mytable. I want to update an element called
> > myelement with the following
> >
> > UPDATE MyTable SET
> > xml.modify
> > ('replace value of
> > (/root/child/grandchild/myelement)[1] with
> > xs:dateTime("2002-05-30T09:30:10Z")')
> > WHERE id = '00000000-0000-0000-0000-000000000000'
> >
> > But I got
> > XQuery [mytable.xml.modify()]: The target of 'replace value of' must be a
> > non-metadata attribute or an element with simple typed content, found
> > 'element(myelement,xdt:untyped) ?'
> >
> > If I removed "[1]" in the query, I got
> > XQuery [mytable.xml.modify()]: The target of 'replace' must be at most one
> > node, found 'element(myelement,xdt:untyped) *'
> >
> > I am sure it has only one instance of the element in the xml with the
> > given
> > id.
> >
> > What is the problem?
>
>
> >> Stay informed about: xml update |
|
| Back to top |
|
 |  |
External

Since: Sep 14, 2004 Posts: 13
|
(Msg. 5) Posted: Wed May 21, 2008 4:26 pm
Post subject: Re: xml update [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
myelement is an xml element with datetime type. So it looks like
<myelement>2008-05-21T09:50:56.531Z</myelement>
"Martin Honnen" wrote:
> Roy wrote:
> > I have id and xml columns in mytable. I want to update an element called
> > myelement with the following
> >
> > UPDATE MyTable SET
> > xml.modify
> > ('replace value of
> > (/root/child/grandchild/myelement)[1] with
> > xs:dateTime("2002-05-30T09:30:10Z")')
> > WHERE id = '00000000-0000-0000-0000-000000000000'
> >
> > But I got
> > XQuery [mytable.xml.modify()]: The target of 'replace value of' must be a
> > non-metadata attribute or an element with simple typed content, found
> > 'element(myelement,xdt:untyped) ?'
>
> How does the current content of that 'myelement' look, does it contain
> child elements?
>
> --
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/
> >> Stay informed about: xml update |
|
| Back to top |
|
 |  |
External

Since: Apr 20, 2007 Posts: 48
|
(Msg. 6) Posted: Wed May 21, 2008 4:26 pm
Post subject: Re: xml update [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Roy wrote:
> myelement is an xml element with datetime type. So it looks like
> <myelement>2008-05-21T09:50:56.531Z</myelement>
Try whether
UPDATE MyTable SET
xml.modify
('replace value of
(/root/child/grandchild/myelement/text())[1] with
xs:dateTime("2002-05-30T09:30:10Z")')
WHERE id = '00000000-0000-0000-0000-000000000000'
works.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/ >> Stay informed about: xml update |
|
| Back to top |
|
 |  |
External

Since: Sep 14, 2004 Posts: 13
|
(Msg. 7) Posted: Wed May 21, 2008 4:26 pm
Post subject: Re: xml update [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
It does not complain and shows "(1 row(s) affected)". However, it I open the
table, the value is not updated.
Any idea?
"Martin Honnen" wrote:
> Roy wrote:
> > myelement is an xml element with datetime type. So it looks like
> > <myelement>2008-05-21T09:50:56.531Z</myelement>
>
> Try whether
>
> UPDATE MyTable SET
> xml.modify
> ('replace value of
> (/root/child/grandchild/myelement/text())[1] with
> xs:dateTime("2002-05-30T09:30:10Z")')
> WHERE id = '00000000-0000-0000-0000-000000000000'
>
> works.
>
> --
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/
> >> Stay informed about: xml update |
|
| Back to top |
|
 |  |
External

Since: Apr 20, 2007 Posts: 48
|
(Msg. 8) Posted: Thu May 22, 2008 1:06 pm
Post subject: Re: xml update [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Roy wrote:
> It does not complain and shows "(1 row(s) affected)". However, it I open the
> table, the value is not updated.
That sounds rather odd. Are you sure the update does not happen?
I tried a simply example with a variable of type xml and that works fine:
DECLARE @x xml;
SET @x = '<root>
<foo>2008-05-22T00:00:00Z</foo>
</root>';
SELECT @x;
SET @x.modify('
replace value of (/root/foo/text())[1]
with xs:dateTime("2002-05-30T09:30:10Z")
');
SELECT @x;
I don't understand why it would not work with a table field. Maybe
someone else does have an idea.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/ >> Stay informed about: xml update |
|
| Back to top |
|
 |  |
External

Since: Oct 21, 2010 Posts: 1
|
(Msg. 9) Posted: Thu Oct 21, 2010 9:51 am
Post subject: Re: xml update [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
For the first error, you can tell it you are trying to set the text of the element if it is untyped.
UPDATE MyTable SET
xml.modify
('replace value of
(/root/child/grandchild/myelement/text())[1] with
xs:dateTime("2002-05-30T09:30:10Z")')
WHERE id = '00000000-0000-0000-0000-000000000000'
For the second error, I don't believe it matters whether there is only one such element in your XML; I reckon it is parsing the XPath first and doesn't believe it's guaranteed to result in exactly one instance and therefore generates the error. I've even seen this when my schema guarantees that there is only one such element and it makes no difference
> On Wednesday, May 21, 2008 11:35 AM Ro wrote:
> I have id and xml columns in mytable. I want to update an element called
> myelement with the following
>
> UPDATE MyTable SET
> xml.modify
> ('replace value of
> (/root/child/grandchild/myelement)[1] with
> xs:dateTime("2002-05-30T09:30:10Z")')
> WHERE id = '00000000-0000-0000-0000-000000000000'
>
> But I got
> XQuery [mytable.xml.modify()]: The target of 'replace value of' must be a
> non-metadata attribute or an element with simple typed content, found
> 'element(myelement,xdt:untyped) ?'
>
> If I removed "[1]" in the query, I got
> XQuery [mytable.xml.modify()]: The target of 'replace' must be at most one
> node, found 'element(myelement,xdt:untyped) *'
>
> I am sure it has only one instance of the element in the xml with the given
> id.
>
> What is the problem?
>> On Wednesday, May 21, 2008 11:44 AM Joe Fawcett wrote:
>> Is the XML column typed?
>>
>> --
>>
>> Joe Fawcett (MVP - XML)
>>
>> http://joe.fawcett.name
>>> On Wednesday, May 21, 2008 11:51 AM Ro wrote:
>>> I do not have xsd associated with the column.
>>>
>>> "Joe Fawcett" wrote:
>>>> On Wednesday, May 21, 2008 12:15 PM Martin Honnen wrote:
>>>> Roy wrote:
>>>>
>>>> How does the current content of that 'myelement' look, does it contain
>>>> child elements?
>>>>
>>>> --
>>>>
>>>> Martin Honnen --- MVP XML
>>>> http://JavaScript.FAQTs.com/
>>>>> On Wednesday, May 21, 2008 12:48 PM Ro wrote:
>>>>> myelement is an xml element with datetime type. So it looks like
>>>>> <myelement>2008-05-21T09:50:56.531Z</myelement>
>>>>>
>>>>> "Martin Honnen" wrote:
>>>>>> On Wednesday, May 21, 2008 1:11 PM Martin Honnen wrote:
>>>>>> Roy wrote:
>>>>>>
>>>>>> Try whether
>>>>>>
>>>>>> UPDATE MyTable SET
>>>>>> xml.modify
>>>>>> ('replace value of
>>>>>> (/root/child/grandchild/myelement/text())[1] with
>>>>>> xs:dateTime("2002-05-30T09:30:10Z")')
>>>>>> WHERE id = '00000000-0000-0000-0000-000000000000'
>>>>>>
>>>>>> works.
>>>>>>
>>>>>> --
>>>>>>
>>>>>> Martin Honnen --- MVP XML
>>>>>> http://JavaScript.FAQTs.com/
>>>>>>> On Wednesday, May 21, 2008 2:13 PM Ro wrote:
>>>>>>> It does not complain and shows "(1 row(s) affected)". However, it I open the
>>>>>>> table, the value is not updated.
>>>>>>> Any idea?
>>>>>>>
>>>>>>> "Martin Honnen" wrote:
>>>>>>>> On Thursday, May 22, 2008 7:06 AM Martin Honnen wrote:
>>>>>>>> Roy wrote:
>>>>>>>>
>>>>>>>> That sounds rather odd. Are you sure the update does not happen?
>>>>>>>>
>>>>>>>> I tried a simply example with a variable of type xml and that works fine:
>>>>>>>>
>>>>>>>> DECLARE @x xml;
>>>>>>>>
>>>>>>>> SET @x = '<root>
>>>>>>>> <foo>2008-05-22T00:00:00Z</foo>
>>>>>>>> </root>';
>>>>>>>>
>>>>>>>> SELECT @x;
>>>>>>>>
>>>>>>>> SET @x.modify('
>>>>>>>> replace value of (/root/foo/text())[1]
>>>>>>>> with xs:dateTime("2002-05-30T09:30:10Z")
>>>>>>>> ');
>>>>>>>>
>>>>>>>> SELECT @x;
>>>>>>>>
>>>>>>>>
>>>>>>>> I don't understand why it would not work with a table field. Maybe
>>>>>>>> someone else does have an idea.
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>>
>>>>>>>> Martin Honnen --- MVP XML
>>>>>>>> http://JavaScript.FAQTs.com/
>>>>>>>> Submitted via EggHeadCafe - Software Developer Portal of Choice
>>>>>>>> ASP.NET MaskedTextBox Custom Control
>>>>>>>> http://www.eggheadcafe.com/tutorials/aspnet/39a071cd-9f96-4e81-9346-4e...181d645 >> Stay informed about: xml update |
|
| Back to top |
|
 |  |
| Related Topics: | Update SQL2005 table with XML Performance - Has anyone done any performance testing with updating db records via an xml data type see http://groups.google.com/group/microsoft.public.sqlserver.xml/browse_thread/thread/3ec91642ff242f13?hl=en versus updating with multiple SQL update statements?
Update table with XML column via linked server - Hi. There is limitation of xml support from SQL server 2005. Xml data type is not supported in distributed queries. So the workaround is to use openquery. But is there a workaround to insert/update the table with XML through linked server? Or this is not...
Update DB Date Field when importing xml with SQLXML - I'm importing xml files into a relational database using SQLXML through C# into SQLExpress I have the data going in ok but the tables have Date fields I'd like to add with each record. This field is set to NOT NULL. Obviously, with this field set to....
xml to SQL DB - We have some large existing Xml files that we'd like to store in the SQL server. We don't want to store just the Xml stream, but we rather like to build the hierarchical structure that represents the Xml in SQL and store the Xml that way. We also want...
how to store a word document in sql server - I Need help on how to store a word document in sql server.what datatype and how to convert it to store it. Pleas Help Thank you |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|
 |
|
|