xquery

Insert element into XML using XQuery and Java

馋奶兔 提交于 2020-01-05 10:40:06
问题 I need to insert a new element into an XML document using XQuery insert expression. I am using saxon as a java api. I am new to XQuery so I am not sure about the exact structure of the insert expression. Can anyone help me in this please. My XML file looks like the following: <?xml version="1.0" encoding="ISO-8859-1"?> <breakfast_menu> <food> <name>Belgian Waffles</name> <price>$5.95</price> <description>two of our famous Belgian Waffles with plenty of real maple syrup<description> <calories

Insert element into XML using XQuery and Java

蹲街弑〆低调 提交于 2020-01-05 10:39:23
问题 I need to insert a new element into an XML document using XQuery insert expression. I am using saxon as a java api. I am new to XQuery so I am not sure about the exact structure of the insert expression. Can anyone help me in this please. My XML file looks like the following: <?xml version="1.0" encoding="ISO-8859-1"?> <breakfast_menu> <food> <name>Belgian Waffles</name> <price>$5.95</price> <description>two of our famous Belgian Waffles with plenty of real maple syrup<description> <calories

Get the specific word in text in HTML page

不打扰是莪最后的温柔 提交于 2020-01-05 08:11:37
问题 If I have the following HTML page <div> <p> Hello world! </p> <p> <a href="example.com"> Hello and Hello again this is an example</a></p> </div> I want to get the specific word for example 'hello' and change it to 'welcome' wherever they are in the document Do you have any suggestion? I will be happy to get your answers whatever the type of parser you use? 回答1: This is easy to do with XSLT. XSLT 1.0 solution : <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

Get the specific word in text in HTML page

前提是你 提交于 2020-01-05 08:11:20
问题 If I have the following HTML page <div> <p> Hello world! </p> <p> <a href="example.com"> Hello and Hello again this is an example</a></p> </div> I want to get the specific word for example 'hello' and change it to 'welcome' wherever they are in the document Do you have any suggestion? I will be happy to get your answers whatever the type of parser you use? 回答1: This is easy to do with XSLT. XSLT 1.0 solution : <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

How to use the XQuery fn:idref() function?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-05 07:26:15
问题 I can't get the XQuery function fn:idref() to return anything. I have this XML document doc.xml ; <doc> <foo idref="xyz"/> <bar xml:id="xyz"/> </doc> And this XQuery; let $d := doc("doc.xml") return $d/idref("xyz") But the result is always empty. I'm guessing that the attribute idref="xyz" needs to be declared as type idref but can that be done without a schema? I'm using Saxon XQuery 1.0 processor. 回答1: Yes, the idref() function only retrieves attributes labelled as being IDREFs, and that

XQuery get Random Text from a List

纵然是瞬间 提交于 2020-01-05 03:30:11
问题 Suppose I have a list of 100 String Element and I want to get 50 of these random Text string to be returned Randomly. I try to do this: let $list := ("a","b",..."element number 100") return xdmp:random(100) This query return one string, I want to return back 50 strings that are distinct from each other. 回答1: Easiest to order by xdmp:random() and limit to the first 50: (for $x in (1 to 100) order by xdmp:random() return $x )[1 to 50] 回答2: xdmp:random() (as well as xdmp:elapsed-time() ) return

Edit XML column using SQL . Not so structured XML

跟風遠走 提交于 2020-01-04 12:42:28
问题 This question is a Follow-Up to this question How to edit XML by getting new tags for ' XXX ', not so structured xml. Need help, I am very new to XML and XQuery. Have to get new tags (nodes) for X if it is none, in case of 1 need to insert 1 only. is there any way to manipulate string on larger scale <NewAttributeRules> <items> <NewAttributeItem> <Scale>CAAA</Scale> <ScaleName>OC07</ScaleName> <comment /> <positiveRules> <NewAttributeRule type="POSITIVE"> <conditions> <InCondition column=

Edit XML column using SQL . Not so structured XML

会有一股神秘感。 提交于 2020-01-04 12:41:32
问题 This question is a Follow-Up to this question How to edit XML by getting new tags for ' XXX ', not so structured xml. Need help, I am very new to XML and XQuery. Have to get new tags (nodes) for X if it is none, in case of 1 need to insert 1 only. is there any way to manipulate string on larger scale <NewAttributeRules> <items> <NewAttributeItem> <Scale>CAAA</Scale> <ScaleName>OC07</ScaleName> <comment /> <positiveRules> <NewAttributeRule type="POSITIVE"> <conditions> <InCondition column=

Xquery group by on 2 tags

家住魔仙堡 提交于 2020-01-03 18:02:46
问题 Below is the XML part of my data. <A> <a><Type>Fruit</Type><Name>Banana</Name></a> <a><Type>Fruit</Type><Name>Orange</Name></a> <a><Type>Fruit</Type><Name>Apple</Name></a> <a><Type>Fruit</Type><Name>Lemon</Name></a> <a><Type>Cars</Type><Name>Toyota</Name></a> <a><Type>Cars</Type><Name>Lamborghini</Name></a> <a><Type>Cars</Type><Name>Renault</Name></a> </A> Out put as - <a>Fruits-Banana,Orange,Apple,Lemon</a> <a>Cars-Toyota,Lamborghini,Renault</a> I tried to get the required output by all in

How to list all the URI of all documents in a directory in marklogic

牧云@^-^@ 提交于 2020-01-03 17:47:05
问题 Hi how can i retrieve the URI of all the documents in directory. I create the below xquery to achieve that but that doesn't helps. for $i in xdmp:directory("/Test/performance/results/","infinity") let $k := document-uri(fn:doc($i)) return <li>{$k}</li> 回答1: For efficiency you should use the URI lexicon. cts:uris((), (), cts:directory-query("/Test/performance/results/","infinity")) See https://docs.marklogic.com/cts:uris for documentation. 回答2: How about: xdmp:directory("/Test/performance