QtXmlPatterns was removed from Qt6. How to use XPath in Qt6?
-
Hi,
I try to port my example from PySide2 to PySide6. What to use instead of
QXmlQuery
? I want to use XPath to parse animations from DAE COLLADA:from PySide6.QtXmlPatterns import QXmlQuery # ... path = "assets/armature.dae" if not f.open(QIODevice.OpenModeFlag.ReadOnly): print("Failed to load the file", path) query = QXmlQuery() query.bindVariable("file", f) query.setQuery("doc($file)//*:float_array[substring(@id, string-length(@id) - string-length('Bone_pose_matrix-input-array') + 1) = 'Bone_pose_matrix-input-array']/text()") self.times = query.evaluateToString().strip().split(" ") self.times = [float(i) for i in self.times] #...
-
@8Observer8
Sadly it's gone, and no replacement. See recent XPath 2.0 for Qt6 topic.But there the OP was able to "get libXML2 going". That has nothing to do with Qt, and isn't (directly) available from Python. Given Python, probably your only chance is to find an external non-Qt Python library which you can integrate.
-
@JonB thanks a lot! It is sad that XPath was removed from Qt6. I what to have the same code base for C++ and Python. I think the best solution for me will be to use XML parsing directly without XPath like I used to parse vertices, normals, and texture coordinates:
from PySide6.QtXml import QDomDocument # ... def initVertexBuffers(path: str): xmlDoc = QDomDocument() file = QFile(path) if not file.open(QIODevice.OpenModeFlag.ReadOnly): print("Failed to open the file: " + path) xmlDoc.setContent(file) file.close() vertPosArray = [] normalArray = [] texCoordArray = [] indexArray = [] root = xmlDoc.documentElement() daeElem = root.firstChildElement() while not daeElem.isNull(): if daeElem.tagName() == "library_geometries": geomElem = daeElem.firstChildElement() if geomElem.tagName() == "geometry": meshElem = geomElem.firstChildElement() if meshElem.tagName() == "mesh": meshChildElem = meshElem.firstChildElement() while not meshChildElem.isNull(): floatArrayElem = meshChildElem.firstChildElement() strArray = floatArrayElem.firstChild().toText().data().split(" ") if meshChildElem.attribute("id").endswith("-mesh-positions"): vertPosArray = list(map(float, strArray)) if meshChildElem.attribute("id").endswith("-mesh-normals"): normalArray = list(map(float, strArray)) if meshChildElem.attribute("id").endswith("-mesh-map-0"): texCoordArray = list(map(float, strArray)) if meshChildElem.tagName() == "triangles" or meshChildElem.tagName() == "polylist": pChildElem = meshChildElem.firstChildElement() while not pChildElem.isNull(): if pChildElem.tagName() == "p": strIndices = pChildElem.firstChild().toText().data().split(" ") indexArray = list(map(int, strIndices)) pChildElem = pChildElem.nextSiblingElement() meshChildElem = meshChildElem.nextSiblingElement() daeElem = daeElem.nextSiblingElement() # ...
-
-
Hi,
You might want to check lxml2. It has a Python module so you should be able to re-use your code with ease.
-
@SGaist thanks! It could be a good solution but for a while I don't know how to build external libraries for Android and WebAssembly. I want to be able to make build executables of my applications for Android, Desktop, and WebAssembly. It is why I like Qt very much because it has built-in libraries for parsing XML, JSON, drawing with build-in OpenGL ES, and WebSockets library to make multiplayer game clients for Android, Desktop, and Web. I want to host Node.js game servers with physics engine on free hosting render.com I don't have time to study how to build external libraries for Android and WebAssembly. I only know how to build OpenAL-Soft for Android to play 3D sounds and how to call Web Audio API from WebAssembly.