Reputation: 21
How do I get the parent for the current item in an xpath query in qml/qt ?
fn:parent()
isn't implemented, ../
yes but doesn't work for me.
Seems like a focus
problem.
xml example:
<groups>
<group id="A">
<item>bla</item>
<item>blah</item>
</group>
<group id="B">
<item>bla</item>
<item>blah</item>
</group>
<group id="C">
<item>bla</item>
<item>blah</item>
</group>
</groups>
The following XmlRole returns an empty string:
XmlListModel {
query: "/groups/group/item"
XmlRole { name: "group_id"; query: "../@id/string()" }
}
Upvotes: 2
Views: 1289
Reputation: 25
It does appear that you are missing the source tag.... the location of the xml file. Although the other discussion regarding the query syntax is still relevant.
Upvotes: 0
Reputation: 11
Where is the source tag that tell the model from where take the query? You need to declare the source, your ID property is outside of node. And have to declare the namespace used(for example http://www.w3.org/2005/Atom). So i think that your code have to be like:
XmlListModel {
query: "/groups/group/"
namespaceDeclarations: "declare namespace group=\"http://www.w3.org/2005/Atom/\";"
source: "url of your xml file"
XmlRole { name: "group_id"; query: "../@id/string()" }
}
Upvotes: 1
Reputation: 243449
../@id/string()
This is invalid syntax in XPath 1.0.
Are you sure you are using an XPath 2.0 engine?
In XPath 1.0 use:
string(../@id
)
Or, if an expression that selects a node-set is required, then simply use:
../@id
Upvotes: 0
Reputation: 56162
Try this XPath:
../@id
The
string(object?)
function converts an object to a string as follows:
- A node-set is converted to a string by returning the string-value of the node in the node-set that is first in document order. If the node-set is empty, an empty string is returned.
Reference: http://www.w3.org/TR/xpath/#section-String-Functions
Upvotes: 0