In this case, I don't really care how many elements are in the document, just how deep they're nested. It has to do with some legacy code I've inherited , and making sure imported data doesn't exceed an artificial limit the original developers put in.
If there's no easy (or relatively easy) XPath query to do this (I've been going through the MS XML 4 docs), plan "B" would be load the document into a DOM and use the childNodes collection to find out how far it nests (nasty, but do-able).
It's certainly a lot easier to code than plan "B" would be. Is it faster? Probably, since I can do a binary search (sort of) by doubling the number of levels each time until it fails, and then I can narrow down using a further binary search.
i understand how u can use that in a transformation to place that number in the output of the transformation, but...
when ur using a DOM, like Xerces, and u have ur Document object i don't undestand how u can use a XPath expression to return the count since it is a number not a Node object.
do you know how? -There are only 10 types of people in the world, those who understand binary and those who don't-
using xalan in Java. xpath is in org.apache.xpath.*
i have not dug that deep yet so i will do some research. u may have pointed me in a direction that i could not previously see.
also i have used MSXML in C++. now there i don't see any parallel functionality in this regard. perhaps it's time to switch to Xalan in C++ as well. -There are only 10 types of people in the world, those who understand binary and those who don't-
MSXML has its bonuses.. you can use the DOMDocumentObject model to perform transforms in xpath with out an additional xpath engine like JAXEN ... I did some MSXML but I cannot recall ever having to do something like this
Another way to do it would be to create a v. small stylesheet with this operation in it that creates another XML document with a result of that node in it, then select that nodes text value and parse it as an int or sommit..
I believe that if i ever had to do something like this i'd probably do what you were doing before, but nothing hurts in learning a new way eh?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.