Consistent Id of XML output of SQL executed on Data Access Point - exact-online

I run an application on Exact Oline for eco taxes, using XML output with XSL transformation to generate the HTML forms.
A query like:
select * from me
generates:
<?xml version="1.0" encoding="utf-16"?>
<InvantiveDAPOutput xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--ecotaksen.be Invantive Data Access Point (Unofficial)-->
<!--License 'L740757780' registered to Control INFO B.V..-->
<ResultSets>
<ResultSet Id="0">
<Fields>
<Field>
<Id>0</Id>
<Name>CurrentDivision</Name>
<DatabaseDataType>int32</DatabaseDataTyp...
In my XSL I then use for instance:
<xsl:value-of select="//InvantiveDAPOutput/ResultSets/ResultSet[#Id='4']/Rows/Row/entity_name_singular" />
But when I insert a query somewhere in the process, the Id all change. 1 remains 1 for instance, but the numbers after the new inserted query increase by 1.
Is there a smarter way to make the XSL independent of the number of queries and their order?

Just add the desired name of the result set to your query as a hint:
select /*+ result_set_name('myname') */ * from me
The XML will become like:
<ResultSet Id="0" Name="myname">
You can find the full syntax for execution hints in the documentation. This holds for Exact Online as well as other platforms such as Teamleader or salesforce.

Related

Select value in xml field with mysql

I have a field in a sulu cms database.
Table phpcr_nodes and field props
This field is stocked in XML like this:
<?xml version="1.0" encoding="UTF-8"?>
<sv:node xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:rep="internal" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<sv:property sv:name="i18n:en-description" sv:type="String" sv:multi-valued="0">
<sv:value length="2560">MY FIRST ITEM</sv:value>
</sv:property>
<sv:property sv:name="i18n:en-subtitle" sv:type="String" sv:multi-valued="0">
<sv:value length="28">MY SECOND ITEM</sv:value>
</sv:property>
</sv:node>
I would like to catch the value
<sv:value length="2560">MY FIRST ITEM</sv:value>
and
<sv:value length="28">MY SECOND ITEM</sv:value>
I have tried something like this:
SELECT
SUBSTRING_INDEX(ExtractValue(props, '//sv:name="i18n:en-subtitle"'), ' ', 1) AS `subtitle`
from phpcr_nodes
It's a MySQL database, how can I get the value in SQL ?
Thanks in advance
If you need to write queries to PHPCR you should use the jackalope abstraction and its query builder so you can write normal SQL 2 queries and jackalope will convert them based on your adapter into the correct SQL query.
If you are interested how jackalope is converting SQL 2 query into SQL queries have a look at its QOMWalker implementation:
https://github.com/jackalope/jackalope-doctrine-dbal/blob/master/src/Jackalope/Transport/DoctrineDBAL/Query/QOMWalker.php
EXTRACTVALUE(props, '//sv:property[#sv:name="i18n:en-subtitle"]/sv:value')
The "EXTRACTVALUE" is a XPATH so you can also copy your XML into a website like http://xpather.com/ to find the correct xpath for your property selection.

How to query an XML Column within a mySQL Database correct?

I have a mySQL Column, called Data, which field type = LongBlob.
In there, I have an XML Document for every supplier.
The saved XML Document looks like this:
<BarcodeList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Clientgroups>
<clientgroup clientgroupID="0" />
</Clientgroups>
<Articles>
<Article articleID="HS1" articleName="Air HG">
<Configuration>
<Feature selectedValue="846566843718" templateID="UpcCode" />
<Feature selectedValue="14.2" templateID="Diameter" />
<Feature selectedValue="8.6" templateID="RadiusBasecurve" />
</Configuration>
</Article>
</Articles>
</BarcodeList>
Of course, in my real world data, there are a lot of articles within this XML File.
Now, I get the input of: "846566843718" and need the Diameter, RadisuBaseCurve and articleID back.
How can I achieve this?
My mySQL Server Version: 5.7
I tried some SQL code, but this runs more than 1 Minute and without any result.
SELECT * FROM xmldata s WHERE EXTRACTVALUE(s.Data, "//Feature[#selectedValue='846566843718']");
And:
SELECT * FROM xmldata s WHERE EXTRACTVALUE(s.Data, "/BarcodeList/Articles/Article/Configuration/Feature/selectedValue='846566843718']");

MySQL/MariaDB namespaces xml returns null with ExtractValue

I have some xml data on a MariaDB database and need to do some parsing.
I ve tried using the following code to extraxt some values but no matter what i may try i keep getting null as output
SELECT xmlResponse FROM myDataBase.xmlLogging where id = '1' INTO #xml;
SELECT ExtractValue(#xml, 'node2');
tried also count(node2) to try identify if there is somtheting wrong in my syntaxaccording to this
https://mariadb.com/kb/en/mariadb/documentation/sql-structure-and-commands/functions-and-operators/string-functions/extractvalue/
my xml structure looks like this, with namespacess
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns:SMnamespace xmlns:ns="http://somenamespace.com/WS/">
<ns:Error_spcCode>0</ns:Error_spcCode><ns:Error_spcMessage/>
<ListofData xmlns="http://www.vendor.com/namespeceIO">
<node1>
<node2>text</node2>
<node3>text</node3>
<node4/>
</node1>
</ListofData>
</ns:SMnamespace>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>'
MySQL/MariaDB do not support xml namespaces. They support colons in element names however.
The reason that you do not get the node should be an invalid context in you location path try:
SELECT ExtractValue(#xml, '//node2');
Starting an Xpath expression with // means any node in the document.
I found this reference
http://bugs.mysql.com/bug.php?id=51425
and it seems that this is the case for me as well. The xml that i demonstrated was a simplier version of my actual one that contains quite big strings. So it seems as soon as i reduced the string size, i could get a result.

Updating an attribute in XML with MySQL

I have a chunk of XML stored as a string in a MySQL database, and need to update one of the attributes using a query.
Given the following string:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<town>
<road name="Main" direction="north"/>
</town>
I would need to change it to update the attribute direction to a different value:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<town>
<road name="Main" direction="east"/>
</town>
Is there an easy way to accomplish this? Thanks in advance!
EDIT: The query would be ran in a SQL script file containing various other upgrade queries, which is called by a piece of code in Java.
Checkout PHP's simple XML
http://www.php.net/manual/en/class.simplexmlelement.php
$xml=new SimpleXMLElement($xml);
print $xml->road->attributes('direction') = 'east';
I ended up overriding the upgrade process for that version. Through Java and JDBC I looped through every row and used JAXB to gain access to the attribute that needed to be changed. I would have preferred to do it with full SQL queries. :(

XPath to check if all provided pairs of elements exist for an entry

I have the following XML stored in an XML field in a SQL Server 2008 database.
<attributes>
<attribute>
<key>animal</key>
<value>rat</value>
</attribute>
<attribute>
<key>color</key>
<value>black</value>
</attribute>
</attributes>
I'm able to select all the entries from the table which have an 'animal' key with a value of 'rats' with the following xpath in sql.
SELECT *
FROM XmlEvents
WHERE Attributes.exist('/attributes/attribute[key="animal" and value="rat"]') = 1
How would I check for matches with multiple attributes?
I'm trying to find rows where: (Key=Animal & Value=Rat) AND (Key=Color & Value=Black).
(Yes, I could put another .exist with an AND in my WHERE clause but I'm trying to avoid that)
Bonus points if you can lead me in the right direction to make this some-what dynamic. I would love to have a stored procedure or function which could somehow take a list of Key/Value pairs and find all the rows which match everything provided.
XPath allows nested predicates and multiple predicates. You could write
/attributes[attribute[key="animal" and value="rat"]][attribute[key="color" and value="black"]]
or equivalently, but somewhat shorter
/attributes[attribute[key="animal"]/value="rat" and attribute[key="color"]/value="black"]