XPath query of DOM.
-
Are there any plans to support XPath querying of QDomDocument?
I believe it would be useful if it was possible to query a (or part of a) QDomDocument and get a QDomElementList. This could make querying a parsed QDomDocument much easer and may allow us to more easily edit the XML based upon XPath results.
(This has been mentioned before at "http://labs.trolltech.com/forums/topic/167":http://labs.trolltech.com/forums/topic/167 .)
Can anyone suggest an easy way to change the XML based on an XPath (specifically I want to remove elements that match an XPath)?
-
I think it's interesting to look at using XQuery for general XML handling. I started to explore this in my last Qt Quarterly article, "Checking the Weather with XQuery":http://qt.nokia.com/developer/qtquarterly/checking-the-weather-with-xquery, and I'll be writing a follow-up article that looks at visualizing queries for the next issue of QQ (due later this month).
-
Excellent article David, I look forward to reading the next issue.
I have managed to achieve what I wanted using an "XSLT identity transform":http://en.wikipedia.org/wiki/Identity_transform#Example_using_XSLT. -
http://doc.trolltech.com/4.5/qxmlquery.html#running-xpath-expressions
wouldn't it just be possible to fetch these nodes using xPath and then remove them?
-
One possible way, not saying it's good, is to have all your QDomElements in the DOM be hashed with an xmlid. Then you can use a QXmlSerializer receiver and query for the xmlid's of the elements you want. Then you can get your list of elements via the id hash.