2013-01-21 75 views

回答

1

看看這個:http://xerces.apache.org/xerces-c/program-dom-3.html

沒有與DOM文檔的例子還有:

// //創建一個小文檔樹 //

{ 
    XMLCh tempStr[100]; 

    XMLString::transcode("Range", tempStr, 99); 
    DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(tempStr, 0); 

    XMLString::transcode("root", tempStr, 99); 
    DOMDocument* doc = impl->createDocument(0, tempStr, 0); 
    DOMElement* root = doc->getDocumentElement(); 

    XMLString::transcode("FirstElement", tempStr, 99); 
    DOMElement* e1 = doc->createElement(tempStr); 
    root->appendChild(e1); 

    XMLString::transcode("SecondElement", tempStr, 99); 
    DOMElement* e2 = doc->createElement(tempStr); 
    root->appendChild(e2); 

    XMLString::transcode("aTextNode", tempStr, 99); 
    DOMText*  textNode = doc->createTextNode(tempStr); 
    e1->appendChild(textNode); 

    // optionally, call release() to release the resource associated with the range after done 
    DOMRange* range = doc->createRange(); 
    range->release(); 

    // removedElement is an orphaned node, optionally call release() to release associated resource 
    DOMElement* removedElement = root->removeChild(e2); 
    removedElement->release(); 

    // no need to release this returned object which is owned by implementation 
    XMLString::transcode("*", tempStr, 99); 
    DOMNodeList* nodeList = doc->getElementsByTagName(tempStr); 

    // done with the document, must call release() to release the entire document resources 
    doc->release(); 
}; 

..等等。

編輯:

但我怎麼加載HTML到DOMDocument和搜索對html元素?這是什麼林試圖弄清楚。

XercesDOMParser解析器;

parser.loadGrammar( 「grammar.dtd」,語法:: DTDGrammarType);

parser.setValidationScheme(XercesDOMParser :: Val_Always);

處理程序處理程序;

parser.setErrorHandler(&處理程序);

parser.parse( 「xmlfile.xml」);

+0

但是,如何將HTML加載到DOMDocument中並針對html元素進行搜索?那就是我試圖弄清楚的。 – jkushner