以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XML工具及XML开发环境 』  (http://bbs.xml.org.cn/list.asp?boardid=7)
----  请教关于xml4c的使用  (http://bbs.xml.org.cn/dispbbs.asp?boardid=7&rootid=&id=146)


--  作者:luling98
--  发布时间:11/10/2003 11:13:00 AM

--  请教关于xml4c的使用
有没有哪位大侠用过的,可不可以指导一番,或者推荐能够了解相关信息的站点?不甚感激啊!!
--  作者: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;
    }


--  作者:Yinjs
--  发布时间:12/19/2003 9:32:00 AM

--  
在取得node后,用node->getFirstChild() ,在用node->getNodeValue()
就可取出来了。
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms