-- 作者:Yinjs
-- 发布时间:12/17/2003 1:54:00 PM
--
我现在属性值可以拿出来,但是NodeValue拿不出来。 一起参考吗。 #include <xercesc/dom/DOM.hpp> #include <xercesc/util/XMLString.hpp> #include <xercesc/util/PlatformUtils.hpp> #include <iostream.h> XERCES_CPP_NAMESPACE_USE class XStr { public : // ----------------------------------------------------------------------- // Constructors and Destructor // ----------------------------------------------------------------------- XStr(const char* const toTranscode) { // Call the private transcoding method fUnicodeForm = XMLString::transcode(toTranscode); } ~XStr() { XMLString::release(&fUnicodeForm); } // ----------------------------------------------------------------------- // Getter methods // ----------------------------------------------------------------------- const XMLCh* unicodeForm() const { return fUnicodeForm; } private : // ----------------------------------------------------------------------- // Private data members // // fUnicodeForm // This is the Unicode XMLCh format of the string. // ----------------------------------------------------------------------- XMLCh* fUnicodeForm; }; #define X(str) XStr(str).unicodeForm() int main (int argc, char* args[]) { try { XMLPlatformUtils::Initialize(); } catch (const XMLException& toCatch) { char* message = XMLString::transcode(toCatch.getMessage()); cout << "Error during initialization! :\n" << message << "\n"; XMLString::release(&message); return 1; } XMLCh tempStr[100]; XMLString::transcode("LS", tempStr, 99); DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempStr); DOMBuilder* parser = ((DOMImplementationLS*)impl)->createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, 0); // optionally you can set some features on this builder if (parser->canSetFeature(XMLUni::fgDOMValidation, true)) parser->setFeature(XMLUni::fgDOMValidation, true); if (parser->canSetFeature(XMLUni::fgDOMNamespaces, true)) parser->setFeature(XMLUni::fgDOMNamespaces, true); if (parser->canSetFeature(XMLUni::fgDOMDatatypeNormalization, true)) parser->setFeature(XMLUni::fgDOMDatatypeNormalization, true); // optionally you can implement your DOMErrorHandler (e.g. MyDOMErrorHandler) // and set it to the builder //DOMErrorHandler* errHandler = new DOMErrorHandler(); //parser->setErrorHandler(errHandler); char* xmlFile = "d:\\ttt.xml"; DOMDocument *doc = 0; try { cout << "begin" << endl; doc = parser->parseURI(xmlFile); /*DOMNodeList *nodelist = doc->getElementsByTagName(X("data")); for(unsigned int i=0; i < doc->getElementsByTagName(X("data"))->getLength() ; i++){ DOMNode *node = nodelist->item(i); const XMLCh* ch = node->getNodeName(); */ DOMElement * dome = doc->getDocumentElement () ; DOMNodeList *nodelist = dome->getElementsByTagName(X("data")); for(unsigned int i=0; i < doc->getElementsByTagName(X("data"))->getLength() ; i++){ //DOMNode *node = nodelist->item(i); DOMText * node = ( DOMText *)(nodelist->item(i)); //const XMLCh* ch = dome->getAttribute(X("CRCTYPE")) ; //const XMLCh* ch3 = node->getAttribute (X("name")); //cout << " " << XMLString::transcode(ch3) << endl; const XMLCh* ch4 = node->getNodeValue (); cout << " " << XMLString::transcode(ch4) << endl; //const DOMTypeInfo* info = node->getTypeInfo () ; //DOMAttr * doma = node->getAttributeNode(X("*")); //const XMLCh* ch4 = doma->getValue (); //const XMLCh* ch4 = info->getName(); //cout << " " << XMLString::transcode(ch4) << endl; //const XMLCh* ch1 = node->getNodeName(); // DOMElement * de = (node->getOwnerDocument())->getDocumentElement () ; // const XMLCh* ch4 = de->getTagName (); //cout << XMLString::transcode(ch4) << endl; // cout << XMLString::transcode(ch1) << endl; } const XMLCh* ch = dome->getAttribute(X("CRCTYPE")) ; const XMLCh* ch2 = dome->getTagName (); cout << XMLString::transcode(ch2) << endl; //DOMAttr * domatt = dome->getAttributeNode(X("CRCTYPE")); //const XMLCh* ch3 = domatt->getName (); //cout << XMLString::transcode(ch3) << endl; //short shint =node->getNodeType(); //const XMLCh* ch1 = node->getNodeValue(); //DOMNamedNodeMap * map = node->getAttributes () ; //DOMNode *node3 = map->getNamedItem(X("SMAPSML")); // const XMLCh* ch2 = node3->getNodeName(); // cout << XMLString::transcode(ch2) << endl; //for(int j=0;j<map->getLength();j++){ // DOMNode *node1 = map->item(i); // const XMLCh* ch1 = node->getNodeName(); // cout << XMLString::transcode(ch1) << endl; //} cout << XMLString::transcode(ch) << endl; // } } catch (const XMLException& toCatch) { char* message = XMLString::transcode(toCatch.getMessage()); cout << "Exception message is: \n" << message << "\n"; XMLString::release(&message); return -1; } catch (const DOMException& toCatch) { char* message = XMLString::transcode(toCatch.msg); cout << "Exception message is: \n" << message << "\n"; XMLString::release(&message); return -1; } catch (...) { cout << "Unexpected Exception \n" ; return -1; } parser->release(); // delete errHandler; return 0; }
|