xerces-c-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erik Rydgren" <erik.rydg...@mandarinen.se>
Subject RE: Parser
Date Thu, 06 Nov 2003 13:47:36 GMT
You should not use the nextNode method. It iterates ALL nodes in the
tree in order. Use firstChild and nextSibling instead.

 

/ Erik

 

-----Original Message-----
From: Milan Tomic [mailto:milan@setcce.org] 
Sent: den 6 november 2003 14:44
To: xerces-c-dev@xml.apache.org
Subject: RE: Parser

 

 

    I have one problem. Both createTreeWalker() and createNodeIterator()
goes through ALL nodes in the XML document. It should iterate only
through child nodes of first given node (root node in this example).
Here is code sample:

 

DOMTreeWalker* walker = theDOM->createTreeWalker(rootElem,
DOMNodeFilter::SHOW_ELEMENT, NULL, true);

for ( tmpNode = (DOMElement*)walker->nextNode(); tmpNode != 0; tmpNode =
(DOMElement*)walker->nextNode() )
{
  char *strValue = XMLString::transcode( tmpNode->getNodeName() );
  ShowMessage(strValue);
  XMLString::release(&strValue);
}

 

    It iterates through ALL nodes in the document, but it should show
only child nodes (elements) of root node.

 

Thanks.

 

Milan

 

 

-----Original Message-----
From: Erik Rydgren [mailto:erik.rydgren@mandarinen.se] 
Sent: Wednesday, November 05, 2003 4:30 PM
To: xerces-c-dev@xml.apache.org
Subject: RE: Parser

It looks correct to me. Do you really see #text nodes while traversing
the tree through iterator->nextNode() ? That is weird.

Now I'm all out of answers. Sorry.

 

/ Erik

 

-----Original Message-----
From: Milan Tomic [mailto:milan@setcce.org] 
Sent: den 5 november 2003 16:13
To: xerces-c-dev@xml.apache.org
Subject: RE: Parser

 

 

    I'm using this:

 

DOMNodeIterator* iterator = theDOM->createNodeIterator(rootElem,
DOMNodeFilter::SHOW_ELEMENT, NULL, true);

 

    but I still see #text "nodes". Am I missing something? I'd like to
see only real elements (i.e. <SomeElement/>), nothing else.

 

Thank you.

 

 

-----Original Message-----
From: Erik Rydgren [mailto:erik.rydgren@mandarinen.se] 
Sent: Wednesday, November 05, 2003 2:33 PM
To: xerces-c-dev@xml.apache.org
Subject: RE: Parser

Use the createTreeWalker method or createNodeIterator method on the
DOMDocument.

 

/ Erik

 

-----Original Message-----
From: Milan Tomic [mailto:milan@setcce.org] 
Sent: den 5 november 2003 13:04
To: xerces-c-dev@xml.apache.org
Subject: RE: Parser

 

 

Thank you.

 

> easiest is to create a tree iterator that doesn't show text nodes
while traversing the DOM tree.

 

How can I do that?

 

Milan

 

 

-----Original Message-----
From: Erik Rydgren [mailto:erik.rydgren@mandarinen.se] 
Sent: Wednesday, November 05, 2003 12:58 PM
To: xerces-c-dev@xml.apache.org
Subject: RE: Parser

That is standard DOM behavior. The carage-return line-feed characters
you have mixed into the XML are treated as non ignorable text content.
Hence text nodes are created.

There are several ways to solve your problem but the easiest is to
create a tree iterator that doesn't show text nodes while traversing the
DOM tree.

 

Another way is to remove ignorable whitespace during parsing, but that
requires that validation is on and that you have a schema that tells the
parser which white space is ignorable and which is not.

 

/ Erik

 

-----Original Message-----
From: Milan Tomic [mailto:milan@setcce.org] 
Sent: den 5 november 2003 12:22
To: Xerces-C
Subject: Parser

 

 

    I'm iterating through nodes: 

tmpNode =
(DOMElement*)tmpNode->getChildNodes()->item(atoi(nodePos.c_str())); 

    but I got some strange "tags" with "#text" name when parser found
$0D$0A bytes between two tags. How can I disable this? I'd like parser
to retrive only valid tags and if found $0D$0A between tags to ignore it
as a "tag".

Thank you. 


Mime
View raw message