本文整理汇总了C++中DOMDocument::createCDATASection方法的典型用法代码示例。如果您正苦于以下问题:C++ DOMDocument::createCDATASection方法的具体用法?C++ DOMDocument::createCDATASection怎么用?C++ DOMDocument::createCDATASection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMDocument
的用法示例。
在下文中一共展示了DOMDocument::createCDATASection方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
docFirstElementChildChild->setAttributeNS(XMLUni::fgXMLNSURIName, X("xmlns:NS1"), X("http://testclash.com"));
//clash with standard prefix
docFirstElementChildChild->setAttributeNS(X("http://testattr5.com"), X("po:attr10"), X("value"));
doc->normalizeDocument();
normalizer->serializeNode(doc);
XERCES_STD_QUALIFIER cout << "\n\n";
//2 prefix with the same uri
docFirstElementChildChild = doc->createElementNS(X("http://www.uri1.com"),X("docEleChildChild6"));
docFirstElementChild->appendChild(docFirstElementChildChild);
docFirstElementChildChild->setAttributeNS(XMLUni::fgXMLNSURIName, X("xmlns:uri1"), X("http://www.uri1.com"));
docFirstElementChildChild->setAttributeNS(XMLUni::fgXMLNSURIName, X("xmlns:uri1b"), X("http://www.uri1.com"));
docFirstElementChildChild->setAttributeNS(X("http://www.uri1.com"), X("uri1:attr1"), X("value"));
docFirstElementChildChild->setAttributeNS(X("http://www.uri1.com"), X("uri1b:attr2"), X("value"));
doc->normalizeDocument();
normalizer->serializeNode(doc);
XERCES_STD_QUALIFIER cout << "\n\n";
//check to see we use the nearest binding and for more inheritence
DOMElement *docFirstElementChildChildChild = doc->createElementNS(X("http://www.uri1.com"),X("docEleChildChildChild"));
docFirstElementChildChild->appendChild(docFirstElementChildChildChild);
docFirstElementChildChild->setAttributeNS(XMLUni::fgXMLNSURIName, X("xmlns:nearerThanPo"), X("http://www.test.com"));
docFirstElementChildChildChild->setAttributeNS(X("http://testattr.com"), X("attr2"), X("value"));
docFirstElementChildChildChild->setAttributeNS(X("http://www.test.com"), X("attr1"), X("value"));
doc->normalizeDocument();
normalizer->serializeNode(doc);
XERCES_STD_QUALIFIER cout << "\n\n";
//NS1.1 stuff
//test creating default prefix when NS1 has been set to ""
noNamespaceEle->setAttributeNS(XMLUni::fgXMLNSURIName, X("xmlns:NS1"), X(""));
DOMElement *noNamespaceChild = doc->createElementNS(X("http://testclash.com"),X("testing1.1Stuff"));
noNamespaceEle->appendChild(noNamespaceChild);
doc->normalizeDocument();
normalizer->serializeNode(doc);
noNamespaceChild = doc->createElementNS(X("http://testclash.com"),X("NS1:testing1.1Stuff"));
noNamespaceEle->appendChild(noNamespaceChild);
noNamespaceChild->setAttributeNS(X("http://www.someRandomUri.com"), X("attr"), X("value"));
doc->normalizeDocument();
normalizer->serializeNode(doc);
//check error conditions
XERCES_STD_QUALIFIER cout << "error conditions" << XERCES_STD_QUALIFIER endl;
DOMConfiguration *conf = doc->getDOMConfig();
conf->setParameter(XMLUni::fgDOMErrorHandler, normalizer);
conf->setParameter(XMLUni::fgDOMNamespaces, true);
DOMElement *level1Node = doc->createElement(X("level1Node"));
docFirstElement->appendChild(level1Node);
doc->normalizeDocument();
docFirstElement->removeChild(level1Node);
docFirstElement->setAttribute(X("level1Attr"), X("level1"));
doc->normalizeDocument();
docFirstElement->removeAttribute(X("level1Attr"));
//cant check this as Xerces does not let us do it
// noNamespaceChild->setAttributeNS(X("http://www.someRandomUri.com"), X("xmlns"), X("value"));
// doc->normalizeDocument();
//lets do a sanity test on a comment
DOMComment *comment = doc->createComment(X("some comment"));
docFirstElement->appendChild(comment);
doc->normalizeDocument();
normalizer->serializeNode(doc);
conf->setParameter(XMLUni::fgDOMComments, false);
docFirstElement->appendChild(comment);
doc->normalizeDocument();
normalizer->serializeNode(doc);
//and on a CDATA
DOMCDATASection *cData = doc->createCDATASection(X("some cdata"));
docFirstElement->appendChild(cData);
doc->normalizeDocument();
normalizer->serializeNode(doc);
conf->setParameter(XMLUni::fgDOMCDATASections, false);
docFirstElement->appendChild(cData);
doc->normalizeDocument();
normalizer->serializeNode(doc);
delete normalizer;
delete tmpTrue;
delete tmpFalse;
return 0;
}
示例2: main
//.........这里部分代码省略.........
XMLString::transcode("Attr01", tempStr, 3999);
DOMAttr* attr01 = doc->createAttribute(tempStr);
DOMNode* rem = E11->setAttributeNode(attr01);
if (rem)
rem->release();
XMLString::transcode("FirstSiblingChild2", tempStr, 3999);
DOMElement* E112 = doc->createElement(tempStr);
E11->appendChild(E112);
XMLString::transcode("SecondSiblingChild1", tempStr, 3999);
DOMElement* E121 = doc->createElement(tempStr);
E12->appendChild(E121);
XMLString::transcode("Attr01", tempStr, 3999);
DOMAttr* attr02 = doc->createAttribute(tempStr);
rem = E12->setAttributeNode(attr02);
if (rem)
rem->release();
XMLString::transcode("SecondSiblingChild2", tempStr, 3999);
DOMElement* E122 = doc->createElement(tempStr);
E12->appendChild(E122);
XMLString::transcode("ThirdSiblingChild1", tempStr, 3999);
DOMElement* E131 = doc->createElement(tempStr);
E13->appendChild(E131);
XMLString::transcode("DocComment", tempStr, 3999);
DOMComment* comment = doc->createComment(tempStr);
root->appendChild(comment);
XMLString::transcode("DocCDataSection", tempStr, 3999);
DOMCDATASection* cdataSec = doc->createCDATASection(tempStr);
E11->appendChild(cdataSec);
XMLString::transcode("DocPI", tempStr, 3999);
XMLCh piStr[] = {chLatin_D, chLatin_o, chLatin_c, chLatin_P, chLatin_I, chNull};
DOMProcessingInstruction* docPI = doc->createProcessingInstruction(piStr, tempStr);
E13->appendChild(docPI);
/*
following are whatToShow types:
SHOW_ALL = 0x0000FFFF,
SHOW_ELEMENT = 0x00000001,
SHOW_ATTRIBUTE = 0x00000002,
SHOW_TEXT = 0x00000004,
SHOW_CDATA_SECTION = 0x00000008,
SHOW_ENTITY_REFERENCE = 0x00000010,
SHOW_ENTITY = 0x00000020,
SHOW_PROCESSING_INSTRUCTION = 0x00000040,
SHOW_COMMENT = 0x00000080,
SHOW_DOCUMENT = 0x00000100,
SHOW_DOCUMENT_TYPE = 0x00000200,
SHOW_DOCUMENT_FRAGMENT = 0x00000400,
SHOW_NOTATION = 0x00000800
*/
////////// NodeIterator Test Cases ////////////////
{
// all node iterating test
DOMNode* node = doc->getFirstChild();
示例3: replaceWholeText
DOMText* DOMTextImpl::replaceWholeText(const XMLCh* newText)
{
DOMDocument *doc = getOwnerDocument();
DOMTreeWalker* pWalker=doc->createTreeWalker(doc->getDocumentElement(), DOMNodeFilter::SHOW_ALL, NULL, true);
pWalker->setCurrentNode((DOMNode*)this);
// Logically-adjacent text nodes are Text or CDATASection nodes that can be visited sequentially in document order or in
// reversed document order without entering, exiting, or passing over Element, Comment, or ProcessingInstruction nodes.
DOMNode* pFirstTextNode=this;
DOMNode* prevNode;
while((prevNode=pWalker->previousNode())!=NULL)
{
if(prevNode->getNodeType()==ELEMENT_NODE || prevNode->getNodeType()==COMMENT_NODE || prevNode->getNodeType()==PROCESSING_INSTRUCTION_NODE)
break;
pFirstTextNode=prevNode;
}
// before doing any change we need to check if we are going to remove an entity reference that doesn't contain just text
DOMNode* pCurrentNode=pWalker->getCurrentNode();
DOMNode* nextNode;
while((nextNode=pWalker->nextNode())!=NULL)
{
if(nextNode->getNodeType()==ELEMENT_NODE || nextNode->getNodeType()==COMMENT_NODE || nextNode->getNodeType()==PROCESSING_INSTRUCTION_NODE)
break;
if(nextNode->getNodeType()==ENTITY_REFERENCE_NODE)
{
DOMTreeWalker* pInnerWalker=doc->createTreeWalker(nextNode, DOMNodeFilter::SHOW_ALL, NULL, true);
while(pInnerWalker->nextNode())
{
short nodeType=pInnerWalker->getCurrentNode()->getNodeType();
if(nodeType!=ENTITY_REFERENCE_NODE && nodeType!=TEXT_NODE && nodeType!=CDATA_SECTION_NODE)
throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
}
pInnerWalker->release();
}
}
DOMText* retVal=NULL;
// if the first node in the chain is a text node, replace its content, otherwise create a new node
if(newText && *newText)
{
if(!castToNodeImpl(pFirstTextNode)->isReadOnly() && (pFirstTextNode->getNodeType()==TEXT_NODE || pFirstTextNode->getNodeType()==CDATA_SECTION_NODE))
{
pFirstTextNode->setNodeValue(newText);
retVal=(DOMText*)pFirstTextNode;
}
else
{
if(getNodeType()==TEXT_NODE)
retVal=doc->createTextNode(newText);
else
retVal=doc->createCDATASection(newText);
pFirstTextNode->getParentNode()->insertBefore(retVal, pFirstTextNode);
}
}
// now delete all the following text nodes
pWalker->setCurrentNode(pCurrentNode);
while((nextNode=pWalker->nextNode())!=NULL)
{
if(nextNode->getNodeType()==ELEMENT_NODE || nextNode->getNodeType()==COMMENT_NODE || nextNode->getNodeType()==PROCESSING_INSTRUCTION_NODE)
break;
if(nextNode!=retVal)
{
// keep the tree walker valid
pWalker->previousNode();
nextNode->getParentNode()->removeChild(nextNode);
nextNode->release();
}
}
pWalker->release();
return retVal;
}