Closed bdonauba closed 1 year ago
Hello, regarding the first query, the attribute pos is bound to the element "posi_id", so maybe the intended query was: //stock[./posi_id/@pos=0]
For the second one, there is a data mismatch, because the data in XML are not number, but text. You can use //stock[./posi_id/text()='2144541'] or //stock[number(./posi_id/text())=2144541]
In my opinion the behavior of QXmlEdit is correct.
Best regards.
Okay now that I know I can deal with it but I want to remark that all the tools (XSLT processor, Java XML Parser) I use and used do type conversion in XPATH automatically. That's astonishing to me that different XPATH implementations exist.
Check for example https://xslttest.appspot.com/
Enter the XML document:
<?xml version="1.0" encoding="UTF-8"?>
<ausgaben>
<daten>
<stock>
<posi_id pos="0">2144541</posi_id>
</stock>
</daten>
</ausgaben>
Enter the transformation with the XPATH expression:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output omit-xml-declaration="yes" indent="no"/>
<xsl:template match="/">
<xsl:for-each select="//stock[posi_id=2144541]">
<xsl:copy-of select="posi_id"/>
<xsl:value-of select="' '"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
See the result:
<posi_id pos="0">2144541</posi_id>
For XPath QXmlEdit is using Qt libraries as documented in Qt docs:
https://doc.qt.io/qt-5/xmlprocessing.html
Okay the difference is obviously Xpath 2.0 versus Xpath 1.0.
From https://en.wikipedia.org/wiki/XPath_2.0:
The main difference is that XPath 1.0 was more relaxed about type conversion, for example comparing two strings ("4" > "4.0") was quite possible but would do a numeric comparison; in XPath 2.0 this is defined to compare the two values as strings using a context-defined collating sequence.
Thank you for your support.
I have this little XPath expression that should work
//stock[@pos=0]
. Unfortunately it does not find the node in my XML document.If I change the XPath expression to something like that //stock[posi_id=2144541] it even throws an error.
Here's the message:
That means translated:
Here is my test XML:
Regards, Bernhard Donaubauer