xquery-sql

Parsing XML with namespaces in SQL Server

痴心易碎 提交于 2019-12-05 04:48:11
问题 I am having a hard time trying to parse an XML that has some namespaces defined: <TravelItineraryReadRS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="2.2.0"> <TravelItinerary xmlns="http://webservices.sabre.com/sabreXML/2011/10"> <CustomerInfo> <PersonName WithInfant="false" NameNumber="01.01" RPH="1"> <GivenName>JEFF S</GivenName>" The XMl is stored in an XML type column named response, and I want to get the GivenName value, for

How to optimise the 'XQuery' SQL

两盒软妹~` 提交于 2019-12-04 12:23:42
I have an XML hierarchy like this in an XML type column of a table with 10,000 records- <Root> <Elem1> <Parent1> <Separator> <Child1/> </Separator> </Parent1> </Elem1> </Root> I have a query like this - DECLARE @Root VARCHAR(50) DECLARE @Entity VARCHAR(50) DECLARE @ParentNode VARCHAR(50) DECLARE @Separator VARCHAR(50) DECLARE @ChildNode VARCHAR(50) SET @Root = 'Root' SET @Entity = 'Elem1' SET @ParentNode = 'Parent1' SET @Separator = 'separator' SET @ChildNode = 'Child1' select Parent.P.value('.', 'varchar(max)') as MyValue, T.uniqueId, T.XMLCol from [XMLTable] as T cross apply (SELECT XMLTable

Parsing XML with namespaces in SQL Server

只谈情不闲聊 提交于 2019-12-03 21:23:06
I am having a hard time trying to parse an XML that has some namespaces defined: <TravelItineraryReadRS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="2.2.0"> <TravelItinerary xmlns="http://webservices.sabre.com/sabreXML/2011/10"> <CustomerInfo> <PersonName WithInfant="false" NameNumber="01.01" RPH="1"> <GivenName>JEFF S</GivenName>" The XMl is stored in an XML type column named response, and I want to get the GivenName value, for which I use the below query: ;WITH XMLNAMESPACES (DEFAULT 'http://webservices.sabre.com/sabreXML/2011/10

selecting individual xml node using SQL

会有一股神秘感。 提交于 2019-12-03 12:45:01
问题 I have a large XML note with many nodes. is there a way that I can select only a single node and all of its contents from the larger XML? i am using sql 2005 回答1: You should use the query() Method if you want to get a part of your XML. declare @XML xml set @XML = ' <root> <row1> <value>1</value> </row1> <row2> <value>2</value> </row2> </root> ' select @XML.query('/root/row2') Result: <row2> <value>2</value> </row2> If you want the value from a specific node you should use value() Method.

selecting individual xml node using SQL

守給你的承諾、 提交于 2019-12-03 02:14:19
I have a large XML note with many nodes. is there a way that I can select only a single node and all of its contents from the larger XML? i am using sql 2005 You should use the query() Method if you want to get a part of your XML. declare @XML xml set @XML = ' <root> <row1> <value>1</value> </row1> <row2> <value>2</value> </row2> </root> ' select @XML.query('/root/row2') Result: <row2> <value>2</value> </row2> If you want the value from a specific node you should use value() Method . select @XML.value('(/root/row2/value)[1]', 'int') Result: 2 Update: If you want to shred your XML to multiple

Updating SQL Server XML node

為{幸葍}努か 提交于 2019-12-02 10:06:40
问题 I am trying to update a node Qty of my XML which is stored inside a SQL Server XML column, no error occurred but my field did not got updated. Please advice. Thanks. XML data copied from SQL Server xml column: <ArrayOfCampaignVoucher xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <CampaignVoucher> <VouCode>Vouch002</VouCode> <Qty>4</Qty> </CampaignVoucher> <CampaignVoucher xsi:nil="true" /></ArrayOfCampaignVoucher> Stored procedure: USE [c1

XQuery and Node Ids

白昼怎懂夜的黑 提交于 2019-12-02 04:14:12
I have this variable: declare @xmlDoc XML it has the following xml stored in it: <?xml version="1.0" encoding="utf-8"?> <NewDataSet> <Table1> <Sharedparam>shared</Sharedparam> <Antoher>sahre</Antoher> <RandomParam2>Good stuff</RandomParam2> <MoreParam>and more</MoreParam> <ResultsParam>2</ResultsParam> </Table1> <Table1> <RandomParam2>do you</RandomParam2> <MoreParam>think</MoreParam> <ResultsParam>2</ResultsParam> </Table1> <Table1> <Sharedparam>Last</Sharedparam> <Antoher> Set </Antoher> <RandomParam2> of </RandomParam2> <MoreParam>values</MoreParam> <ResultsParam>are here</ResultsParam> <

Sort all attributes of XML in SQL query using XQuery

谁都会走 提交于 2019-12-01 20:10:05
问题 How can get the XML with sorted attributes using XQuery in SQL? for example for this XML: <root><book b='' c='' a=''/></root> must return: <root><book a='' b='' c=''/></root> 回答1: From Limitations of the xml Data Type. The order of attributes in an XML instance is not preserved. When you query the XML instance stored in the xml type column, the order of attributes in the resulting XML may be different from the original XML instance. So even if you could figure out a way of sorting the

Sort all attributes of XML in SQL query using XQuery

寵の児 提交于 2019-12-01 18:16:35
How can get the XML with sorted attributes using XQuery in SQL? for example for this XML: <root><book b='' c='' a=''/></root> must return: <root><book a='' b='' c=''/></root> From Limitations of the xml Data Type . The order of attributes in an XML instance is not preserved. When you query the XML instance stored in the xml type column, the order of attributes in the resulting XML may be different from the original XML instance. So even if you could figure out a way of sorting the attributes, you can not trust that the XML data type in SQL Server will preserve the order you want. Attributes

How to Extract data from xml column in sql 2008

回眸只為那壹抹淺笑 提交于 2019-12-01 12:39:21
问题 I have a table with a column of type xml. I have to extract the values from the xml column. I have tried all possible ways and i couldn succeed.Please find below the sample of the xml data. <Menu> <Id>1</Id> <Url>http://www.zmtcdn.com/menus/1211/menu-photo-for-barbeque-nation-1.jpg</Url> </Menu> <Menu> <Id>2</Id> <Url>http://www.zmtcdn.com/menus/1211/menu-photo-for-barbeque-nation-2.jpg</Url> </Menu> <Menu> <Id>3</Id> <Url>http://www.zmtcdn.com/menus/1211/menu-photo-for-barbeque-nation-3.jpg<