xquery

SQL Server : FOR XML sorting control by attribute

最后都变了- 提交于 2019-12-19 02:52:52
问题 I am generating a XML file from a SQL Server query. I have some problem about sorting elements issues. For example, there is simple code as below. <test> <tree abc="123"/> <tree abc="789"/> <tree-order abc="456"/> </test> As you can see tree and tree-order are different elements and I want to sort by attributes as <test> <tree abc="123"/> <tree-order abc="456"/> <tree abc="789"/> </test> like this. Anyone has good idea to solve this problem? Thank you. Sorry I have detail question as below AS

How to get a particular attribute from XML element in SQL Server

笑着哭i 提交于 2019-12-17 15:53:47
问题 I have something like the following XML in a column of a table: <?xml version="1.0" encoding="utf-8"?> <container> <param name="paramA" value="valueA" /> <param name="paramB" value="valueB" /> ... </container> I am trying to get the valueB part out of the XML via TSQL So far I am getting the right node, but now I can not figure out how to get the attribute. select xmlCol.query('/container/param[@name="paramB"]') from LogTable I figure I could just add /@value to the end, but then SQL tells me

How can I use xpath querying using R's XML library?

房东的猫 提交于 2019-12-17 13:56:10
问题 The xml file has this snippet: <?xml version="1.0"?> <PC-AssayContainer xmlns="http://www.ncbi.nlm.nih.gov" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:schemaLocation="http://www.ncbi.nlm.nih.gov ftp://ftp.ncbi.nlm.nih.gov/pubchem/specifications/pubchem.xsd" > .... <PC-AnnotatedXRef> <PC-AnnotatedXRef_xref> <PC-XRefData> <PC-XRefData_pmid>17959251</PC-XRefData_pmid> </PC-XRefData> </PC-AnnotatedXRef_xref> </PC-AnnotatedXRef> I tried to parse it using xpath's global search and also

Getting cdata content while parsing xml file

 ̄綄美尐妖づ 提交于 2019-12-17 09:52:10
问题 I have an xml file <?xml version="1.0" encoding="utf-8"?> <xml> <events date="01-10-2009" color="0x99CC00" selected="true"> <event> <title>You can use HTML and CSS</title> <description><![CDATA[This is the description ]]></description> </event> </events> </xml> I used xpath and and xquery for parsing the xml. $xml_str = file_get_contents('xmlfile'); $xml = simplexml_load_string($xml_str); if(!empty($xml)) { $nodes = $xml->xpath('//xml/events'); } i am getting the title properly, but iam not

Execute a XQuery with PHP

人盡茶涼 提交于 2019-12-17 07:47:45
问题 How to execute a XQuery in PHP? Can you give me an example? Thank you. 回答1: pear package: http://www.pecl.php.net/package/Zorba (error 404 link) NEW (2011): http://www.zorba-xquery.com/html/entry/2011/12/27/PHP_Meets_XQuery zorba documentation: http://www.zorba-xquery.com/ zorba docs provide a simple example: //Include for the Object-Oriented API require ‘zorba_api.php’; //Initialization of Zorba store $store = InMemoryStore::getInstance(); //Initialization of Zorba $zorba = Zorba:

Is there a JSON equivalent of XQuery/XPath?

限于喜欢 提交于 2019-12-17 02:27:07
问题 When searching for items in complex JSON arrays and hashes, like: [ { "id": 1, "name": "One", "objects": [ { "id": 1, "name": "Response 1", "objects": [ // etc. }] } ] Is there some kind of query language I can used to find an item in [0].objects where id = 3 ? 回答1: Yup, it's called JSONPath. The source is now on GitHub. It's also integrated into DOJO. 回答2: I think JSONQuery is a superset of JSONPath and thus replaces it in dojo. Then there's also RQL. From Dojo documentation: JSONQuery is an

How can I query a value in SQL Server XML column

我的梦境 提交于 2019-12-16 22:37:31
问题 I have following XML stored in a XML column (called Roles ) in a SQL Server database. <root> <role>Alpha</role> <role>Beta</role> <role>Gamma</role> </root> I'd like to list all rows that have a specific role in them. This role passed by parameter. 回答1: select Roles from MyTable where Roles.value('(/root/role)[1]', 'varchar(max)') like 'StringToSearchFor' These pages will show you more about how to query XML in T-SQL: Querying XML fields using t-sql Flattening XML Data in SQL Server EDIT

NSXMLDocument, search with nodesForXPath:

天大地大妈咪最大 提交于 2019-12-14 04:25:23
问题 I need to search through an HTML document for two specific strings of text in cocoa. I am creating an NSXMLDocument with the web page: Page Example Then I am trying to search it for the app title, and the url of the icon. I am currently using this code to search for the specific strings: NSString *xpathQueryStringTitle = @"//div[@id='desktopContentBlockId']/div[@id='content']/div[@class='padder']/div[@id='title' @class='intro has-gcbadge']/h1"; NSString *xpathQueryStringIcon = @"//div[@id=

How to check IDREFS length in xPath

南笙酒味 提交于 2019-12-14 04:08:24
问题 I have the next DTD definition <!ELEMENT testNode EMPTY> <!ATTLIST testNode listOfNodes IDREFS #REQUIRED bestNode IDREF #REQUIRED > when I get /testNode/@listOfNodes I have to check if there are more then one ref in listOfNodes . How can I do this ? 回答1: If you have multiple IDREF vlues in attribute listOfNodes, it must be separated by space as per DTD rules. So, you may follow this example to check multiple values: let $x := <testNode listOfNodes="d1 d2"/> return if(contains($x/@listOfNodes,

Compare Xml data in SQL

醉酒当歌 提交于 2019-12-14 03:54:20
问题 I have two tables with same NVARCHAR field that really contains XML data. in some cases this really-XML-field is really same as one row in other table but differs in attributes order and therefor string comparison does not return the correct result!!! and to determining the same XML fields ,I need to have a comparison like: cast('<root><book b="" c="" a=""/></root>' as XML) = cast('<root><book a="" b="" c=""/></root>' as XML) but I get this Err Msg: The XML data type cannot be compared or