Hi,
or you can use Pathan (software.decisionsoft.com), an open source
XPath module for xerces-c that my company maintains (soon to be XPath2!!).
Gareth
On 15 Jul 2003, Gr�ndal Daniel wrote:
> Hi!
>
> Well, I guess I have to start using Xalan then. I can't always know the depth
> of the xPath expression, since the argument to countNodes is variable (i.e.
> user input). Getting the nodenames are probably an easy task (just need to
> parse the argument string for '/'), but since I don't know the depth I can't
> really do this in Xerces then...Or I guess I could do it with a recursive
> function. Anyway, it seems easier to start learning Xalan right away. It can't
> be that hard. =)
>
> Thanks!
>
> //daniel
>
>
> Erik Rydgren (2003-07-14 21:47):
> >You are right this us usually a job for a XPath engine like Xalan. But
> >it is very doable in DOM as well as long as your search is static to
> >it's nature and doesn't change. According to your question you'll only
> >need a double nested loop to accomplish the task you described.
> >Something like this.
> >(Watch out for pseudo code)
> >
> >unsigned int nNumFound = 0;
> >DOMElement* poRoot = doc->getDocumentElement();
> >if (compareNodeName(poRoot, "root")) {
> > DOMElement* poRootChild = poRoot->GetFirstChild();
> > while (poRootChild) {
> > if (compareNodeName(poRootChild, "level1")) {
> > DOMElement* poChildChild = poRootChild->getFirstChild();
> > while(poChildChild) {
> > if (compareNodeName(poChildChild, "level2"))
> > nNumFound++;
> >
> > poChildChild = poChildChild->getNextSibling();
> > }
> > }
> > poRootChild = poRootChild->getNextSibling();
> > }
> >}
> >
> >As I said. This is usually best done in Xalan but if you need a small
> >footprint and can't handle the overhead applied by Xalan then do it in
> >DOM.
> >But Xalan WILL make your application more flexible and easier to
> >maintain when requirements change.
> >
> >Regards
> >Erik Rydgren
> >Mandarin IT
> >Sweden
> >
> >> -----Original Message-----
> >> From: Gr�ndal Daniel [mailto:[EMAIL PROTECTED]
> >> Sent: den 14 juli 2003 21:09
> >> To: [EMAIL PROTECTED]
> >> Subject: Help with xPath and DOM
> >>
> >> Hi!
> >>
> >> I am kind of new to this stuff and right now I'm trying to count the
> >> number of
> >> nodes that fulfils a xPath-expression.
> >> What I want to do i simple "countNodes(const std::string &xPath)".
> >>
> >> I should probably do this with Xalan (or?), but can I do it with
> >Xerces?
> >>
> >> This is what I do (roughly) before I want to cound the nodes (I do it
> >for
> >> other
> >> reasons and that's why I want to continue to use my already created
> >> parser):
> >>
> >> impl =
> >>
> >DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("LS
> >")
> >> );
> >> parser = ((DOMImplementationLS*)
> >> impl)->createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, 0);
> >>
> >> // set some features on parserobject...
> >>
> >> doc = parser->parseURI(const_cast<char*>(xml.c_str()));
> >>
> >> // use doc to useful stuff
> >>
> >> This should give me a DOM-tree right in doc?
> >> So now I want to do doc.countNodes("/root/level1/level2"); // how many
> >> nodes is
> >> there that looks like this: <root><level1><level2>?
> >>
> >> I should not be impossible to do something like that...=)
> >>
> >> Thanks for any suggestions!
> >>
> >> //daniel
> >>
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
> >
>
> ------------------------------------------------------------------
> RFV Data E-post: [EMAIL PROTECTED]
> Utvecklingsenheten/Grupp 2 Tfn: 060-187126
> S.a J�rnv�gsgatan 41 Mobil: 070-3016517
> 851 93 Sundsvall Fax: 060-147870
> ------------------------------------------------------------------
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
--
Gareth Reakes, Head of Product Development +44-1865-203192
DecisionSoft Limited http://www.decisionsoft.com
XML Development and Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]