DominicWatson Posted July 6, 2007 Share Posted July 6, 2007 Hi there, I'm wondering if it's possible to build an XPath expression that will return just the names of the elements that it selects? At present my code to extract this data is exceedingly slow!Thanks in advance,Dominic Link to comment Share on other sites More sharing options...
boen_robot Posted July 6, 2007 Share Posted July 6, 2007 Yes, and quite easily btw. Just use the name() funciton after the targeted node. For example: /*/name() will return the name of the root node of the XML, regardless of what that element is called.If you're using JavaScript, you can use the document.evaluate() object to cast a single XPath expression (as a string argument to this function) and get the node set as an object. There's only one problem, and if you have enough JavaScript knowledge already, you'll know it better then I do - IE. Yep, IE doesn't support the evaluate() object, and a few others btw. Link to comment Share on other sites More sharing options...
DominicWatson Posted July 11, 2007 Author Share Posted July 11, 2007 Yes, and quite easily btw. Just use the name() funciton after the targeted node. For example:/*/name() will return the name of the root node of the XML, regardless of what that element is called. Hey, thanks for the reply. Unfortunately that produces an error for me (my XPath tool doesn't see it as a valid expression). Using Coldfusion with the following java class for using XPath: 'org.apache.xpath.CachedXPathAPI'Thanks again,Dominic Link to comment Share on other sites More sharing options...
boen_robot Posted July 11, 2007 Share Posted July 11, 2007 Hey, thanks for the reply. Unfortunately that produces an error for me (my XPath tool doesn't see it as a valid expression). Using Coldfusion with the following java class for using XPath: 'org.apache.xpath.CachedXPathAPI'Thanks again,DominicStrange. It should have worked. Try local-name() instead. Link to comment Share on other sites More sharing options...
aalbetski Posted July 19, 2007 Share Posted July 19, 2007 in XPATH and XMLDOM, you would use the nodeName propertyi.e.document.write(oXML.selectSingleNode("//element[@id=1]").nodeName) Link to comment Share on other sites More sharing options...
ashvini Posted July 22, 2007 Share Posted July 22, 2007 Hi there, I'm wondering if it's possible to build an XPath expression that will return just the names of the elements that it selects? At present my code to extract this data is exceedingly slow!Thanks in advance,DominicHi Waston,In coldfusion, Xpath expression to get element name from source XML file.Use- Let Sample XML<catalog><book name="name1">..</book>..</catalog>"/catalog/name()"Try, and let me know your result. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.