xquery

Xquery to extract text

I am working on extracting text out of html documents and storing in database. I am using webharvest tool for extracting the content. However I kind of stuck at a point. Inside webharvest I use XQuery expression inorder to extract the data. The html document that I am parsing is as follows: <td><a name="hw">HELLOWORLD</a>Hello world</t...

using an attribute name in an xQuery

Hi all! I have this Xml: <Item key = "id"> <SubItem id = "1" a = "2"/> <SubItem id = "1" b = "3"/> <SubItem x = "1"/> <SubItem y = "1"/> <SubItem z = "1"/> </Item> I wish to select the SubItems that have an attribute whose name equals the value of. key Meaning I want a query that returns these guys: <SubItem id = "1...

How to get the value of an attribute whose name is not a literal in xQuery?

For example: let $targetAtt "= "att1"; let $doc := <Xml att1 = "la", att2 = "la la"> So this works: return $doc/@*[(name(.) = $targetAtt)] But is a more succinct syntax possible? For example: the following Does not work such as return $doc/@$targetAtt. Thanks ! ...

SQL Server XML Column exist() query

Assuming I have a SQL Server 2005 table with an xml column containing the following values: CREATE TABLE XmlTest ( XMLid int, Data xml) INSERT XMLTest VALUES ( 1 , '<data><item><type v="1" /><value v="12.56" /></item><item><type v="3" /><value v="DEBIT" /></item></data>' ) INSERT XMLTest VALUES ( 2 , '<data><item><type v...

how to set xquery context document in java using saxon 9.2he?

how do I execute this xquery for $elem in /root/element() return $elem on an xml file using java without using fn:doc? i keep getting XPDY0002: The context item for axis step child::element(xml, xs:anyType) is undefined --the rundown: I need a simple solution to load an xml file, load an xquery and process ...

Get the most repeated element in a sequence with XQuery

Hello, I've got a sequence of values. They can all be equal... or not. So with XQuery I want to get the most frequent item in the sequence. let $counter := 0, $index1 := 0 for $value in $sequence if (count(index-of($value, $sequence))) then { $counter := count(index-of($value, $sequence)) $index1 := index-of($value) } else {} ...

Xquery nodes value

I need to get the value of AccountName in my table <rows> <Row xmlns="http://adcenter.microsoft.com/advertiser/reporting/v5/XMLSchema"&gt; <AccountName value="MA_Yellowpages - AdStore" /> </Row> </rows> I am using below thing - ;WITH XMLNAMESPACES('http://adcenter.microsoft.com/advertiser/reporting/v5/XMLSchema' AS ns) select...

Xquery parsing text with <a> tags

I am using XQuery to extract content from html pages. The html body structure is of this kind: <td> <a href ="hw1">xyz </a> Hello world 1 <a href="hw2">Helloworld 2</a> Helloworld 3 </td> My XQuery expression for extracting the text is as follows: //a[starts-with(@href,'hw1')]/following...

XQuery extract between two tags

I am currently working on extracting data from html. I would like to extract the text between two tags. <p class="xfHeading"><b>XYZ:</b></p> <p>asdfghjk</p> <p>sdsdsd</p> <p>asdvcvcfghjk</p> <p class="xfHeading"><b>ABC:</b></p> <P>fvgbhnjm</P> <p cl...

Does XQuery have exit statement for FLOWR expressions

I would like to know if xquery FLOWR expression has an exit statement like continue and break? For example I want to exit the for loop when a particular condition is reach. ...

Using XSpec and XQuery - how to execute XQuery statement on context

Heya, We've got a series of XML documents that have validation operations performed on them via XQuery to locate whether nodes exist in the document and if they hold the right values. We would like to introduce some unit testing for all these XQuery statements, similar to the unit testing introduced for XSLTs however we've hit a slight...

Embedding XQuery in Java

Hi I need to retrieve some details from a MusicXML (xml) file in Java. I managed to read xml files in java - but through a web service (where I have to be online, connected to internet when I'm running my code). I came across XQuery where you can easily extract info from an XML file. But I need to embed XQuery in java (i.e. use xquery ...

SQL Server 2005 XML Query problem with ".exist" method

I have this XML Query in SQL Server 2005: SElECT XmlField FROM tablename WHERE xmlField.exist('(/Root/Name[id="10")[1]') = 1 However, I want to replace the value "10" with a parameter that I pass to the Stored Procedure. How do I achieve this? I have tried using "@variablename" but it doesn't work. Thanks in advance. ...

What index would speed up my XQuery in X-Hive / Documentum xDB?

I have approx 2500 documents in my test database and searching the xpath /path/to/@attribute takes approximately 2.4 seconds. Doing distinct-values(/path/to/@attribute) takes 3.0 seconds. I've been able to speed up queries on /path/to[@attribute='value'] to hundreds or tens of milliseconds by adding a Path value index on /path/to[@attr...

check for value before

DECLARE @xVar XML SET @xVar = '<book genre="security" publicationdate="2002" ISBN="0-7356-1588-2"> <title>Writing Secure Code</title> <author> <firstname>Michael</firstname> <lastname>Howard</lastname> <age>25</age> <birthday>2010-05-17T00:00:00</birthday> </author> <author> <firstname></first...

Getting the following sibling in an XPath when "following" axis is not supported.

I am trying to get the text elements of a table that follows a paragraph that contains a specific text element using XQuery on MS SQL Server. The problem is whenever I use the axes "following", "following-sibling" or "previous-sibling", I get an error saying this is not supported in SQL Server (I'm using version 2008). So for instance,...

XML Comparing and sorting query

I have the below xml, in which I need to do the following: If the value of both title and text element are same, sort those list element based on score attribute For e.g.: Here the value of title and text for 1st and 3rd list element are same, so these two should be sort based on score and display the list which has the highest score a...

XQuery if exists conditional insert / replace

What would the XQuery look like to check if a node exists, and if it does then run a replace statement, if not then an insert statement? Here's what I have in mind. I want to store whether or not a user has read an important message in XML. Here's what the data would look like. <usersettings> <message haveRead="0" messageId="23" ><...

org.xml.sax.SAXParseException: Reference is not allowed in prolog

Hi, I am trying to escape html characters of a string and use this string to build a DOM XML using parseXml method shown below. Next, I am trying to insert this DOM document into database. But, when I do that I am getting the following error: org.xml.sax.SAXParseException: Reference is not allowed in prolog. I have three questions: 1...

how namespaces can be read from xml file using xquery

I am reading XML files of Office 2007 document using xquery. In these files the namespaces are also included. I need to retrieve the node of namespaces. I wrote xquery to fetch data and it works fine if I removed namespace from the source XML file else of the xquery resultset is empty. Wanna know how can I read namespaces and value from ...