peiyongz 2002/11/20 14:10:31
Modified: c/tests/ThreadTest ThreadTest.cpp
Log:
Using DOMWriter to dump DOM
Revision Changes Path
1.26 +19 -69 xml-xerces/c/tests/ThreadTest/ThreadTest.cpp
Index: ThreadTest.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/tests/ThreadTest/ThreadTest.cpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- ThreadTest.cpp 15 Nov 2002 21:58:41 -0000 1.25
+++ ThreadTest.cpp 20 Nov 2002 22:10:30 -0000 1.26
@@ -71,6 +71,8 @@
#include <xercesc/dom/DOM.hpp>
+#include <xercesc/framework/StdOutFormatTarget.hpp>
+
XERCES_CPP_NAMESPACE_USE
void clearFileInfoMemory();
@@ -306,7 +308,6 @@
// for DOM, re-walk the tree.
// for SAX, can't do, just return previous
value.
- void domPrint(const DOMNode *node); // Dump out the contents of a node,
void domPrint(); // including any children. Default (no
param)
// version dumps the entire document.
@@ -596,7 +597,23 @@
{
printf("Begin DOMPrint ...\n");
if (gRunInfo.dom)
- domPrint(fXercesDOMParser->getDocument());
+ {
+ try
+ {
+ XMLCh tempStr[100];
+ XMLString::transcode("LS", tempStr, 99);
+ DOMImplementation *impl =
DOMImplementationRegistry::getDOMImplementation(tempStr);
+ DOMWriter *theSerializer =
((DOMImplementationLS*)impl)->createDOMWriter();
+ XMLFormatTarget *myFormTarget = new StdOutFormatTarget();
+ DOMNode *doc = fXercesDOMParser->getDocument();
+ theSerializer->writeNode(myFormTarget, *doc);
+ delete theSerializer;
+ }
+ catch (...)
+ {
+ // do nothing
+ }
+ }
printf("End DOMPrint\n");
}
@@ -607,70 +624,6 @@
delete s;
}
-
-void ThreadParser::domPrint(const DOMNode *node)
-{
-
- DOMNode *child;
- DOMNamedNodeMap *attributes;
-
- switch (node->getNodeType() )
- {
- case DOMNode::ELEMENT_NODE:
- {
- printf("<");
- printString(node->getNodeName()); // the element name
-
- attributes = node->getAttributes(); // Element's attributes
- int numAttributes = attributes->getLength();
- int i;
- for (i=0; i<numAttributes; i++) {
- domPrint(attributes->item(i));
- }
- printf(">");
-
- for (child=node->getFirstChild(); child!=0;
child=child->getNextSibling())
- domPrint(child);
-
- printf("</");
- printString(node->getNodeName());
- printf(">");
- break;
- }
-
-
- case DOMNode::ATTRIBUTE_NODE:
- {
- printf(" ");
- printString(node->getNodeName()); // The attribute name
- printf("= \"");
- printString(node->getNodeValue()); // The attribute value
- printf("\"");
- break;
- }
-
-
- case DOMNode::TEXT_NODE:
- case DOMNode::CDATA_SECTION_NODE:
- {
- printString(node->getNodeValue());
- break;
- }
-
- case DOMNode::ENTITY_REFERENCE_NODE:
- case DOMNode::DOCUMENT_NODE:
- {
- // For entity references and the document, nothing is dirctly
- // printed, but we do want to process the chidren nodes.
- //
- for (child=node->getFirstChild(); child!=0;
child=child->getNextSibling())
- domPrint(child);
- break;
- }
- }
-}
-
-
//----------------------------------------------------------------------
//
// parseCommandLine Read through the command line, and save all
@@ -727,9 +680,6 @@
}
else
throw 1;
- }
- else if (strcmp(argv[argnum], "-dom") == 0) {
- gRunInfo.dom = true;
}
else if (strcmp(argv[argnum], "-reuse") == 0)
gRunInfo.reuseParser = true;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]