You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by Ken <ke...@gmail.com> on 2005/06/14 08:51:28 UTC

Child nodes

Hi,

I have 2 problems / questions

1.

I'm trying to process the child nodes of an element node that was
selected with the use of an evaluator but, although hasChildNodes
returns true, when I try to process the child nodes I always get an
error as if the nodes don't have any callable methods

Here's the code :

----- snip ------

XalanDOMString cFileName = TranscodeFromLocalCodePage(strFile.c_str());
LocalFileInputSource cInputSource(cFileName.c_str());
XalanSourceTreeInit cSourceTreeInit;
XalanSourceTreeDOMSupport cDOMSupport;
XalanSourceTreeParserLiaison cLiaison(cDOMSupport);

cDOMSupport.setParserLiaison(&cLiaison);
				
XalanDocument * pDocument = cLiaison.parseXMLStream(cInputSource);
XalanDocumentPrefixResolver	cPrefixResolver(pDocument);
XPathEvaluator cEvaluator;

XalanElement * pParentNode = 
        reinterpret_cast<XalanElement
*>(cEvaluator.selectSingleNode(cDOMSupport,
				                                                     pDocument,
   TranscodeFromLocalCodePage(XMLP_PARENT.c_str()).c_str(),
                                                                    
cPrefixResolver));

if (pParentNode->hasChildNodes())
{
    XalanNodeList * pListNodes = pParentNode->getChildNodes();

        for (xalanc::size_type i = 0; i < pListNodes->getLength(); ++i)
        {
            const XalanDOMString & strXNodeName =
pListNodes->item(i)->getNodeName();

            switch (pListNodes->item(i)->getNodeType())
            {
              .....
            }
      }
}

---- snip ---

Do I do something wrong ? Do I have to use some transformation in
order to process the child nodes without finding them ?

Interesting enough, if I process the nodes by finding them with the
evaluator, then everything is Ok.

2. I'm trying to find all CDATA nodes in an XML document and I don't
know how should I formulate the query for the evaluator. Any
suggestions ?

Thanks,
Ken

Re: Child nodes

Posted by da...@us.ibm.com.
> 1.
> 
> I'm trying to process the child nodes of an element node that was
> selected with the use of an evaluator but, although hasChildNodes
> returns true, when I try to process the child nodes I always get an
> error as if the nodes don't have any callable methods

The default source tree implementation does not support getChildNodes(). 
You need to use getFirstChild(), then getNextSibling() on each child node 
to go through the list of children.  There are many examples of this in 
the source code.

> 2. I'm trying to find all CDATA nodes in an XML document and I don't
> know how should I formulate the query for the evaluator. Any
> suggestions ?

CDATA sections are not part of the XPath data model, so they are not 
represented in the source tree, and you cannot search for them.

Dave