xerces-c-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Bertoni <dbert...@apache.org>
Subject Re: ELEMENT_NODE appears as TEXT_NODE
Date Sat, 26 Sep 2009 01:42:48 GMT
Kimberly Stewart wrote:
> I'm a novice to both XML authoring and Xerces so I'm working from
> samples to get everything set up.  I've started a simple program to
> parse my sample .xml and output it's contents.
>  
> I was expecting several ELEMENT_NODEs and a few TEXT_NODEs, however my
> output indicates that everything in my .xml is a TEXT_NODE.
This is not possible.

> This is preventing me from being able to access the actual element name,
> and is returning #text as the node name for every node in the DOM tree.
>  
> Any suggestions on why this is occurring and how to correctly identify
> the elements as ELEMENT_NODEs?
Your code must have a bug.

> Thanks!
>  
> Here's the pertinent code:
>  
> // create tree walker to traverse all elements in the DOMDocument Tree
> DOMElement *docRoot = document->getDocumentElement(); // get root to
> give walker
> DOMTreeWalker* walker = document->createTreeWalker(docRoot,
> DOMNodeFilter::SHOW_TEXT, NULL, true);
You're asking the DOMTreeWalker to only show you text nodes, so there's 
no way you'll get any element nodes. Of course, you can always call 
getParent() on each text node, but perhaps you should instead have the 
DOMTreeWalker show you element and text nodes:

DOMTreeWalker* walker =
     document->createTreeWalker(
         docRoot,
         DOMNodeFilter::SHOW_ELEMENT | DOMNodeFilter::SHOW_TEXT,
         NULL,
         true);

Dave

Mime
View raw message