XQuery file returning invalid entity reference using special characters - xquery

I have the following query in a MarkLogic XQuery file, and I am seeing the following error message returned
XDMP-ENTITYREF: (err:XPST0003) Invalid entity reference " " . See the MarkLogic server error log for further detail.
The following is the code I am using in the XQuery file.
xquery version "1.0-ml";
declare variable $query :=
cts:or-query
((
cts:element-word-query(xs:QName("lines"),"l&l"),
cts:element-word-query(xs:QName("lines"),"pool & cue"),
cts:element-word-query(xs:QName("lines"),"look")
));
declare function local:do-query(){
element xml {
for $i in cts:uris( (), (), $query)
let $item := doc($i)
return
element item {
element title { $item/title/string() }
}
}
};
local:do-query()
Obviously the 2x tags i am looking for are l&l and pool & cue. I have also looked into the repair-full suggestion in another question posted, but couldn't figure out how that fits into this query. If I removed the ones with special characters, it works as expected.
Any ideas?

Based on the additional info in the comments to the question, this is not an issue with the execution of the code, but rather with deployment of the code.
This happens often if you insert code using QConsole, or some other ways in which you evaluate XQuery code. The & get interpreted, and translated to the & character it represents. If you then write that into a .xqy file into some Modules database, it does not get escaped back into & again, since XQuery files are stored as plain text in MarkLogic, and & doesn't get escaped in plain text.
A better way to deploy code is by uploading or inserting from disk. That way characters like &, >, and { inside XML won't get interpreted, but preserved and inserted as is. There are tools like ml-gradle and Roxy that make deploying MarkLogic code very easy. Consider using these. Alternatively you could also look into using Curl against the Management REST api.
If you want to use QConsole after all, escape characters like & twice. E.g. & becomes &amp;, and < becomes &lt;.
HTH!

Related

PL/SQL escape character like for statement

I've tried to search but didn't found an answer.
I've created with PL/SQL, HTML, CSS and Javascript a web application.
People can search for article and write a comment to These articles.
If they click the submit button it starts to search with the conditions of the customer.
I send the conditions as param and store them into variables.
After that I start my Statement and refresh the page with the new records.
If someone writes a comment with Special characters like
(&, %, ", ', _)
my page crashes because the Statement string isn't correct anymore.
The Statement Looks like
SELECT * FROM myTable
WHERE Name LIKE ('''%'||nameVar||'%''');
Excuse my english
Thanks
Ok, first your question about "ESCAPING" lead me to the wrong way, because you can define a "ESCAPE" character for a like Statement: This would take your % or _ in your Statement literal:
where ..... like '%\%%' ESCAPE '\'
should find a record with an % in the column.
BUT THATS NOT YOUR PROBLEM!
Your web application has to HTML encode your string - then you can store it in any database.
This has to be done by your frontend (whatever it is: ASP.NET, PHP, etc ...)
After a short Google search I found this: HTF Package, the HTF.ESCAPE_SC function encodes the string to be useable in SQL Statements.
Maybe this link helps you: https://docs.oracle.com/cd/B14099_19/web.1012/b15896/pshtp.htm

parse escaped HTML into node in xqilla

I'm trying to get text from an rss 2.0 feed (description tag) using XQilla. The address is here. This is fine but the tag contains escaped HTML like
"<a href="some_address>..."
It would be useful to have this HTML in a node and further work with it, but I am at a loss here. I can get the tag contents with
let $desc := $item/*[name()='description']
but do not know how to unescape it. I tried parse-html, which only strips the text of tags and returns a string, like the data() function. Searching on the web suggests that extension functions exist for this, but in other parsers. Is there a way to do it in XQilla? By the way, the code I am working on is a JAWS ResearchIt lookup source.
XQilla has – like lots of other XQuery implementations – a proprietary function to load XML and HTML from a string (they don't have anchor tags, thus you need to scroll through the document, I'm sorry).
xqilla:parse-xml($xml as xs:string?) as document-node()?
xqilla:parse-html($html as xs:string?) as document-node()?
Given $desc contains the unparsed HTML, xqilla:parse-html($desc) will return the parse result.

Sparql Query at endpoint

I want to run the following sparql query at an endpoint:
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT DISTINCT ?name WHERE{?person foaf:name ?name.FILTER regex(str(?name), "+ns+","i")}
I'm coding in C# on Visual Studio, and would send this query to the endpoint. It should check the results without any case-senstivity, but writing the query this way gives an error in visual studio. How do I correct it?
Update (based on author's clarification that "i" is where the problem lies):
You need to properly escape the " symbol so that it gets included in the SPARQL query string. Currently the ["] before [i] signals the end of the text string. No wonder you get an error message.
See MSDN: String literals for escaping rules:
either " escape as \" or make the string a C# verbatim literal and escape as ""
Check DotNetRdf documentation for Querying with SPARQL examples.
It shows both how to run SPARQL queries (using DotNetRdf) and how to inject variable values into queries (what you are trying to do with "+ns+" and "i").
Also:
answers.semanticweb.com is a good place to ask Semantic Web / RDF / SPARQL questions
please describe the error you are getting (what Ren asked in comments above)

Using ora:view with XMLTable to Query a Relational Table as XML

I have an Oracle relational table called DOCTYPES with columns ID, DOCTYPE, SUBTYPE.
When I run the following statement in Oracle SQL Developer
SELECT * FROM XMLTable('for $i in ora:view("LAZ", "DOCTYPES")/ROW
return $i/SUBTYPE')
I get back the results between tags as expected. But when I run the following statement I get an error:
SELECT * FROM XMLTable('for $i in ora:view("LAZ", "DOCTYPES")/ROW
return <SUBTYPE="{$i/SUBTYPE}"/>')
LPX-00801: XQuery syntax error at '='. I don't understand why the second statement doesn't work.
Thank you very much for your help in advance.
Don't know what Oracle makes of XQuery, but the statement between the apostrophes clearly has an XQuery syntax error at '=', as IMO was correctly diagnosed.
This is because you are opening a direct element constructor, but an equals sign incorrectly follows the tag name. An equals sign is used inside of a direct element constructor to separate attribute names from attribute values. So the following might work:
SELECT * FROM XMLTable('for $i in ora:view("LAZ", "DOCTYPES")/ROW
return <SUBTYPE name="{$i/SUBTYPE}"/>')
For the specification, please refer to 3.7.1 Direct Element Constructors in the XQuery recommendation.
Syntax was wrong.
SELECT * FROM XMLTable('for $i in ora:view("LAZ", "DOCTYPES")/ROW
return <SUBTYPE="{data($i/SUBTYPE)}"/>')

XQuery: Inserting Nodes

I'm reading in an XML file using XQuery and want to insert several nodes/elements and generate a new XML file. How can I accomplish this?
I've tried using the replace() function, but, it looks like all my XML tags are being stripped when I call doc() to load my document. So calling replace() isn't any good if my XML tags are being removed.
Any help? Are there other technologies I can use?
An extension to the XQuery language allowing updates -- the XQuery Update Facility -- exists to allow documents to be modified.
Inserting a node looks like this:
insert node <foo>bar</foo>
into /bar//baz[id='qux']
Among other engines, this is supported by BaseX.
See http://www.w3.org/TR/xquery-update-10/
replace() is a string operation, so the XML will be converted to a string before replacement.
To create a modified copy of the original file, you can modify an identity transformation which recursively copies the original file to insert the new nodes where required - see the article in the XQuery Wikibook
Alternatively if the file is in an XML database such as eXist, you can use update operations to insert elements in situ.
Using XQuery Scripting you can write programs like this:
variable $stores := doc("stores.xml")/stores;
insert node element store {
element store-number { 4 },
element state { "CA" }
} into $stores;
$stores
You can try such example live at http://www.zorba-xquery.com/html/demo#vpshT+pVURyQSCEOKrFBrF0jyGY=

Resources