Will Sappington wrote:
I’m writing some code that’s loosely based on the SerializeNodeSet example. I evaluate an XPath expression using selectNodeList() which returns a NodeRefList of 3 nodes. Each of them is an element and each of them has 2 child elements, i.e.

<A>

    <B>BVaue</B>

    <C>CVaue</C>

    <D>DVaue</D>

</A>

(repeat twice)

I’m able to walk that list and display the node names and values. I need to descend into the child nodes and get their values. So in a for loop over the list of <A>’s, I get a XalanNode* with the item(i) method and then do a getChildNodes() on that. However, I get compile errors when I try to use the XalanNodeList* that I get back from getChildNodes(). I get “use of undefined type” errors trying to use the node list pointer, specifically:

C:\Proj\src\libs\Profile\Profile.cpp(1588) : error C2027: use of undefined type 'XalanNodeList'

c:\proj\3rdparty\include\xalanc\xalandom\xalannode.hpp(32) : see declaration of 'XalanNodeList'

Well, you need to include the header file that defines the class XalanNodeList, which is src/xalanc/XalanDOM/XalanNodeList.hpp


I’ve tried casting the node pointer to an Element pointer based on some code I found in the list archive, trying to give the node list a type but that was no help. Any help from someone here would be greatly appreciated. Relevant code snippets follow:


Whatever code you found that casts a XalanNodeList pointer to a XalanElement pointer is hopelessly broken, as they are unrelated types.

...
    if (theNodeType == XalanNode::ELEMENT_NODE)

    {

        /* element node */

        if (theNode->hasChildNodes())

        {

            const XalanNodeList* pChildren = pParent->getChildNodes();

//===>      /* ** this line gets a compile error ** */

Once you include the appropriate header file, this will compile. However, depending on which underlying implementation you're using, this may or may not work. The default Xalan source tree implementation does not support getChildNodes(), so if you're using that implementation, an exception will be thrown. The wrapper around the Xerces-C DOM does support this function.

The best way to do this to ensure your code will work with both implementations is to use pParent->getFirstChild(), then use child->getNextSibling() to navigate the children.

Dave

Reply via email to