xquery

SQL Server XML add attribute if non-existent

落爺英雄遲暮 提交于 2019-12-23 16:55:07
问题 I am trying to add an attribute if it does not exist. It should be simple, but I am new to XML XPath/XQuery/etc., so excuse my ignorance. I want to be able to pass XML data and modify it... ALTER FUNCTION [dbo].[ConvertXmlData](@xmlData XML) RETURNS XML AS BEGIN RETURN @xmlData.<something here> END If I pass data like: <something> this is sample data <xxx id="1"/> and <xxx id="2" runat="server" />. More <yyy id="3" /> </something> I would like <something> this is sample data <xxx id="1" runat

XQuery to get list of attributes

做~自己de王妃 提交于 2019-12-23 15:22:27
问题 If I have several Section elements in an XML document, what XQuery do I use to get a list of all the name values? <Section name="New Clients" filePath="XNEWCUST.TXT" skipSection="False"> 回答1: In XPath 2.0 (which is a subset of XQuery) one would use the following expression to get a sequence of all string values of the "name" attributes of the "Section" elements: for $attr in //Section/@name return string($attr) Do note that using the "//" abbreviation is typically a bad practice as this may

search a path between two graph nodes in XQuery

女生的网名这么多〃 提交于 2019-12-23 09:55:49
问题 I'm trying to make an algorithm that searchs and returns a path between two nodes in a graph in xQuery, i've had no luck so far as it returns just one node and it's adyacent nodes. First i should make clear that the graph is a directed graph and every node can have zero, one or more origins, in the XML a node only has the link to it's origin but not to it's following nodes Here's an example of some nodes and their XML <node> <id> 123-456-789</id> <name> something </name> <Links> <Link>

XQuery: how to properly append , in for loop

耗尽温柔 提交于 2019-12-23 08:47:34
问题 So I have xml data like this: <PhoneNumber>213-512-7457</PhoneNumber> <PhoneNumber>213-512-7465</PhoneNumber> and with this XQuery: <PhoneNumberList> { for $phone in $c//PhoneNumber let $phoneStr := "" return concat($phoneStr, $phone) } </PhoneNumberList> I get: <PhoneNumberList>213-512-7457213-512-7465</PhoneNumberList> But I actually want: <PhoneNumberList>213-512-7457, 213-512-7465</PhoneNumberList> Could someone shed some light on how to do this? 回答1: <PhoneNumberList> { string-join($c/

Inserting a child node in an XMLTYPE column

坚强是说给别人听的谎言 提交于 2019-12-23 07:39:11
问题 I have a simple query: WITH xtbl AS ( SELECT XMLTYPE ('<a><b>1</b></a>') AS xcol FROM DUAL ) SELECT XMLQUERY ('copy $tmp := . modify insert node <c>2</c> into $tmp/a/b return $tmp' PASSING xcol RETURNING CONTENT) AS newxcol FROM xtbl; What I'm trying to do is to insert a node <c> after <b> inside the node <a> but Oracle 12c is throwing this error: ORA-19114: XPST0003 - error during parsing the XQuery expression: LPX-00801: XQuery syntax error at 'EOF' 5 - - ^ I want the output as: NEWXCOL ---

get comma separated values from xml data

杀马特。学长 韩版系。学妹 提交于 2019-12-23 05:45:07
问题 I know how to do it in the simplest scenario, e.g. DECLARE @commaSeparatedValues NVARCHAR(MAX) DECLARE @xml XML = N'<id>1</id> <name>test</name> <istest>1</istest>' ;WITH nodes AS ( SELECT Tbl.Col.value('.', 'nvarchar(max)') as Value FROM @xml.nodes('*/text()') Tbl(Col) ), prepareStrings AS ( SELECT IIF(ISNUMERIC(n.value) = 1, n.Value, '''' + n.Value + '''') AS Value FROM nodes n ) SELECT @commaSeparatedValues = CASE WHEN @commaSeparatedValues IS NULL THEN s.Value ELSE @commaSeparatedValues +

How to using for loop using XQuery to delete xml nodes [duplicate]

孤街醉人 提交于 2019-12-23 04:02:06
问题 This question already has answers here : Deleting Multiple Nodes in Single XQuery for SQL Server (2 answers) Closed 5 years ago . I have an XML parameter @Xml in SQL Stored procedure like below: <Root> <Data> <Id>1</Id> <Name>Kevin</Name> <Des>Des1</Des> </Data> <Data> <Id>2</Id> <Name>Alex</Name> <Des>Des2</Des> </Data> <Data> <Id>3</Id> <Name>Amy</Name> <Des>Des3</Des> </Data> </Root> now, I want to delete several nodes in this xml, the filter is like this (Id = 2 AND Name = 'Alex') OR (Id

XPath or XQuery to exclude article sections which only contains lists

ぃ、小莉子 提交于 2019-12-22 17:47:31
问题 I am trying to extract the sections of an article (Introduction, History, Overview....). I look for an XPath to select all the sections which begin with a heading and contain some paragraphs. If they only contain a list, they should be discarded. For example : <h2>Intro</h2> <p> It has paragraph and should be extracted </p> ..... <h2>References </h2> <ul>...It has just list and should be discarded </ul> <h2>...</h2> .... If XPath is not possible, an XQuery could also work. I tried the

How to select an attribute by a variable in xquery?

若如初见. 提交于 2019-12-22 12:26:37
问题 I know how to select an attribute like so: $table/@id However how do I do this if the attribute name is stored as a variable. For example: let $x = "id" $table/@[$x] 回答1: You can use the functions local-name or node-name to capture the value of the attribute and match it the predicate. local-name will simply return a string that matches the element name, and node-name will return a fully qualified name, which is generally recommended, but practically speaking, is only necessary if you are

eXist-db include html template in .xq data

前提是你 提交于 2019-12-22 10:46:13
问题 i have an index.html data where I included the template through: <div xmlns="http://www.w3.org/1999/xhtml" data-template="templates:surround" data-template-with="templates/page.html" data-template-at="content"> At the index html site I included a keyword search form, and the idea is when I click on the search button it should call an .xq file to request the search results: <form method="GET" action="ksearch.xq"> When I submit the form, the ksearch.xq page opens, but even though I include the