本文整理汇总了C++中DOMDocument::createTextNode方法的典型用法代码示例。如果您正苦于以下问题:C++ DOMDocument::createTextNode方法的具体用法?C++ DOMDocument::createTextNode怎么用?C++ DOMDocument::createTextNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMDocument
的用法示例。
在下文中一共展示了DOMDocument::createTextNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: appendElementWithText
void appendElementWithText( DOMNode* cur, DOMNode* reply,
const char* name, const char* text,
int indentLevel, bool indent,
attrVect* attribute ) {
MC2String indentStr( indentLevel*3, ' ' );
indentStr.insert( 0, "\n" );
DOMDocument* doc = XMLTool::getOwner( reply );
DOMElement* textElement = doc->createElement( X( name ) );
if ( text != NULL ) {
textElement->appendChild( doc->createTextNode( X( text ) ) );
}
if ( attribute != NULL ) {
for ( uint32 i = 0 ; i < attribute->size() ; ++i ) {
textElement->setAttribute( X( (*attribute)[ i ].first ),
X( (*attribute)[ i ].second ) );
}
}
// Add textElement to cur
if ( indent ) {
cur->appendChild( doc->createTextNode( X( indentStr.c_str() ) ) );
}
cur->appendChild( textElement );
}
示例2: encodeDName
DOMElement * DSIGKeyInfoName::createBlankKeyName(const XMLCh * name, bool isDName) {
// Create the DOM Structure
safeBuffer str;
DOMDocument *doc = mp_env->getParentDocument();
const XMLCh * prefix = mp_env->getDSIGNSPrefix();
makeQName(str, prefix, "KeyName");
DOMElement *ret = doc->createElementNS(DSIGConstants::s_unicodeStrURIDSIG, str.rawXMLChBuffer());
mp_keyInfoDOMNode = ret;
// Check whether to encode prior to adding
if (isDName == true) {
// Treat as a distinguished name
mp_decodedDName = XMLString::replicate(name);
XMLCh * encodedName = encodeDName(name);
mp_keyNameTextNode = doc->createTextNode(encodedName);
XSEC_RELEASE_XMLCH(encodedName);
}
else
mp_keyNameTextNode = doc->createTextNode(name);
ret->appendChild(mp_keyNameTextNode);
mp_name = mp_keyNameTextNode->getNodeValue();
return ret;
}
示例3: setKeySize
void XENCEncryptionMethodImpl::setKeySize(int size) {
// First map the int to an XMLCh string
XMLCh sizeXMLCh[10];
XMLString::binToText((unsigned int) size, sizeXMLCh, 9, 10);
if (mp_keySizeTextNode == NULL) {
// Get some setup values
safeBuffer str;
DOMDocument *doc = mp_env->getParentDocument();
const XMLCh * prefix = mp_env->getXENCNSPrefix();
makeQName(str, prefix, s_KeySize);
DOMElement *e = doc->createElementNS(DSIGConstants::s_unicodeStrURIXENC, str.rawXMLChBuffer());
mp_encryptionMethodElement->insertBefore(e, mp_encryptionMethodElement->getFirstChild());
mp_env->doPrettyPrint(mp_encryptionMethodElement);
e->appendChild(mp_keySizeTextNode = doc->createTextNode(sizeXMLCh));
}
else {
mp_keySizeTextNode->setNodeValue(sizeXMLCh);
}
}
示例4:
DOMElement * DSIGTransformXPath::createBlankTransform(DOMDocument * parentDoc) {
safeBuffer str;
const XMLCh * prefix;
DOMElement *ret;
DOMDocument *doc = mp_env->getParentDocument();
prefix = mp_env->getDSIGNSPrefix();
// Create the transform node
makeQName(str, prefix, "Transform");
ret = doc->createElementNS(DSIGConstants::s_unicodeStrURIDSIG, str.rawXMLChBuffer());
ret->setAttributeNS(NULL,DSIGConstants::s_unicodeStrAlgorithm, DSIGConstants::s_unicodeStrURIXPATH);
// Create the XPath element
makeQName(str, prefix, "XPath");
mp_xpathNode = doc->createElementNS(DSIGConstants::s_unicodeStrURIDSIG, str.rawXMLChBuffer());
mp_exprTextNode = doc->createTextNode(MAKE_UNICODE_STRING(""));
ret->appendChild(mp_xpathNode);
mp_xpathNode->appendChild(mp_exprTextNode);
mp_txfmNode = ret;
return ret;
}
示例5: toXMLCommon
void EppResponseInfoFeeType::toXMLCommon( DOMDocument &doc, const DOMString &tag, DOMElement& inElement )
{
EppCommandInfoFeeType::toXMLCommon(doc, tag, inElement);
DOMElement* elm = NULL;
if( NULL != this->fee )
{
for( unsigned int i = 0; i < fee->size(); i++ )
{
EppFeeFee* member = fee->elementAt(i);
if( NULL != member )
{
elm = member->toXML(doc, "fee");
if( NULL != elm )
{
inElement.appendChild(elm);
}
}
}
}
if( this->fClass.length() > 0 )
{
elm = doc.createElement(XS("class"));
elm->appendChild(doc.createTextNode(this->fClass));
inElement.appendChild(elm);
}
}
示例6: toXMLCommon
void EppCommandCheckFeeType::toXMLCommon( DOMDocument &doc, const DOMString &tag, DOMElement& inElement )
{
DOMElement* elm = NULL;
if( this->name.length() > 0 )
{
elm = doc.createElement(XS("name"));
elm->appendChild(doc.createTextNode(this->name));
inElement.appendChild(elm);
}
EppCommandInfoFeeType::toXMLCommon(doc, tag, inElement);
}
示例7: handleFile
// 2006/12/16
void handleFile(char* filein, char* fileout, int mode)
{
if (mode==_TXT2TXTMODE) {
int result;
if (filein == NULL) {
if (fileout == NULL) result = seg->segmentStream(cin,cout);
else {
ofstream* fout = new ofstream(fileout);
result = seg->segmentStream(cin,*fout);
fout->close();
}
} else {
ifstream* fin = new ifstream(filein);
ofstream* fout = new ofstream(fileout);
result = seg->segmentStream(*fin,*fout);
fin->close();
fout->close();
}
// BROKEN, result is false 2006/11/07
//if (verbose)
// cerr << "> Segmented in " << result << " sentences." << endl;
}
else if (mode==_TXT2XMLMODE) {
DOMDocument* out = xmlInterface->createDocument("document");
DOMElement* root = out->getDocumentElement();
if (filein != NULL)
root->setAttribute(XMLString::transcode("filename"),
XMLString::transcode(filein));
DOMElement* contents = out->createElement(XMLString::transcode("content"));
DOMElement* body = out->createElement(XMLString::transcode("body"));
DOMElement* section = out->createElement(XMLString::transcode("section"));
section->setAttribute(XMLString::transcode("analyze"),
XMLString::transcode("yes"));
DOMText* text =
out->createTextNode(XMLString::transcode(getFileContents(filein).c_str()));
section->appendChild(text);
body->appendChild(section);
contents->appendChild(body);
root->appendChild(contents);
handleDocument(out,fileout);
}
else if (mode==_XML2XMLMODE) {
handleDocument(xmlInterface->parse(filein),fileout);
}
}
示例8:
DOMElement * DSIGKeyInfoValue::createBlankRSAKeyValue(const char * modulus,
const char * exponent) {
// Set the strings
m_modulus.sbStrcpyIn(modulus);
m_exponent.sbStrcpyIn(exponent);
// Set our type
m_keyInfoType = KEYINFO_VALUE_RSA;
// Create the DOM Structure
safeBuffer str;
DOMDocument *doc = mp_parentSignature->getParentDocument();
safeBuffer prefix = mp_parentSignature->getDSIGNSPrefix();
makeQName(str, prefix, "KeyValue");
DOMElement *ret = doc->createElementNS(DSIGConstants::s_unicodeStrURIDSIG, str.sbStrToXMLCh());
mp_valueNode = ret;
makeQName(str, prefix, "RSAKeyValue");
DOMElement * rsa = doc->createElementNS(DSIGConstants::s_unicodeStrURIDSIG, str.sbStrToXMLCh());
ret->appendChild(doc->createTextNode(DSIGConstants::s_unicodeStrNL));
ret->appendChild(rsa);
rsa->appendChild(doc->createTextNode(DSIGConstants::s_unicodeStrNL));
ret->appendChild(doc->createTextNode(DSIGConstants::s_unicodeStrNL));
// Now create the value children
makeQName(str, prefix, "Modulus");
DOMElement * v = doc->createElementNS(DSIGConstants::s_unicodeStrURIDSIG, str.sbStrToXMLCh());
mp_modulusTextNode = doc->createTextNode(MAKE_UNICODE_STRING(modulus));
rsa->appendChild(v);
rsa->appendChild(doc->createTextNode(DSIGConstants::s_unicodeStrNL));
v->appendChild(mp_modulusTextNode);
makeQName(str, prefix, "Exponent");
v = doc->createElementNS(DSIGConstants::s_unicodeStrURIDSIG, str.sbStrToXMLCh());
mp_exponentTextNode = doc->createTextNode(MAKE_UNICODE_STRING(exponent));
rsa->appendChild(v);
rsa->appendChild(doc->createTextNode(DSIGConstants::s_unicodeStrNL));
v->appendChild(mp_exponentTextNode);
return ret;
}
示例9: setOAEPparams
void XENCEncryptionMethodImpl::setOAEPparams(const XMLCh * params) {
if (mp_oaepParamsTextNode == NULL) {
// Need to create
if (mp_mgfAlgorithmAttr == NULL && mp_digestAlgorithmAttr == NULL && mp_keySizeTextNode == NULL) {
mp_env->doPrettyPrint(mp_encryptionMethodElement);
}
// Get some setup values
safeBuffer str;
DOMDocument *doc = mp_env->getParentDocument();
const XMLCh * prefix = mp_env->getXENCNSPrefix();
makeQName(str, prefix, s_OAEPparams);
DOMNode* inspoint = NULL;
DOMElement *e = doc->createElementNS(DSIGConstants::s_unicodeStrURIXENC, str.rawXMLChBuffer());
if (mp_keySizeTextNode != NULL) {
inspoint = mp_keySizeTextNode->getParentNode()->getNextSibling();
}
else {
inspoint = mp_encryptionMethodElement->getFirstChild();
}
mp_encryptionMethodElement->insertBefore(e, inspoint);
mp_env->doPrettyPrint(mp_encryptionMethodElement);
e->appendChild(mp_oaepParamsTextNode = doc->createTextNode(params));
}
else {
mp_oaepParamsTextNode->setNodeValue(params);
}
}
示例10: createTransformList
void DSIGReference::createTransformList(void) {
// Creates the transforms list
safeBuffer str;
const XMLCh * prefix;
DOMDocument *doc = mp_env->getParentDocument();
prefix = mp_env->getDSIGNSPrefix();
if (mp_transformsNode == NULL) {
// Need to create a transforms node
makeQName(str, prefix, "Transforms");
mp_transformsNode = doc->createElementNS(DSIGConstants::s_unicodeStrURIDSIG, str.rawXMLChBuffer());
mp_referenceNode->insertBefore(mp_transformsNode, mp_referenceNode->getFirstChild());
if (mp_env->getPrettyPrintFlag() == true)
mp_referenceNode->insertBefore(doc->createTextNode(DSIGConstants::s_unicodeStrNL), mp_transformsNode);
mp_env->doPrettyPrint(mp_transformsNode);
// Create the list
XSECnew(mp_transformList, DSIGTransformList());
}
}
示例11: main
int main()
{
try {
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch) {
char *pMessage = XMLString::transcode(toCatch.getMessage());
fprintf(stderr, "Error during XMLPlatformUtils::Initialize(). \n"
" Message is: %s\n", pMessage);
XMLString::release(&pMessage);
return -1;
}
// Create a XMLCh buffer for string manipulation
XMLCh tempStr[4000];
XMLCh featureStr[100];
XMLString::transcode("Traversal",featureStr,99);
//
// Doc - Create a small document tree
//
{
//creating a DOM Tree
/* Tests are based on the tree structure below
doc - root - E11 (attr01) - textNode1
- E111
- E112
- cdataSec
- E12 (attr02) - textNode2
- E121
- E122
- E13 - E131
- docPI
- comment
*/
DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(featureStr);
DOMDocument* doc = impl->createDocument();
//Creating a root element
XMLString::transcode("RootElement", tempStr, 3999);
DOMElement* root = doc->createElement(tempStr);
doc->appendChild(root);
//Creating the siblings of root
XMLString::transcode("FirstSibling", tempStr, 3999);
DOMElement* E11 = doc->createElement(tempStr);
root->appendChild(E11);
XMLString::transcode("SecondSibling", tempStr, 3999);
DOMElement* E12 = doc->createElement(tempStr);
root->appendChild(E12);
XMLString::transcode("ThirdSibling", tempStr, 3999);
DOMElement* E13 = doc->createElement(tempStr);
root->appendChild(E13);
//Attaching texts to few siblings
XMLString::transcode("Text1", tempStr, 3999);
DOMText* textNode1 = doc->createTextNode(tempStr);
E11->appendChild(textNode1);
XMLString::transcode("Text2", tempStr, 3999);
DOMText* textNode2 = doc->createTextNode(tempStr);
E12->appendChild(textNode2);
//creating child of siblings
XMLString::transcode("FirstSiblingChild1", tempStr, 3999);
DOMElement* E111 = doc->createElement(tempStr);
E11->appendChild(E111);
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);
//.........这里部分代码省略.........
示例12: main
int main(int argC, char*[])
{
// Initialize the XML4C2 system.
try
{
XMLPlatformUtils::Initialize();
}
catch(const XMLException& toCatch)
{
char *pMsg = XMLString::transcode(toCatch.getMessage());
XERCES_STD_QUALIFIER cerr << "Error during Xerces-c Initialization.\n"
<< " Exception message:"
<< pMsg;
XMLString::release(&pMsg);
return 1;
}
// Watch for special case help request
int errorCode = 0;
if (argC > 1)
{
XERCES_STD_QUALIFIER cout << "\nUsage:\n"
" CreateDOMDocument\n\n"
"This program creates a new DOM document from scratch in memory.\n"
"It then prints the count of elements in the tree.\n"
<< XERCES_STD_QUALIFIER endl;
errorCode = 1;
}
if(errorCode) {
XMLPlatformUtils::Terminate();
return errorCode;
}
{
// Nest entire test in an inner block.
// The tree we create below is the same that the XercesDOMParser would
// have created, except that no whitespace text nodes would be created.
// <company>
// <product>Xerces-C</product>
// <category idea='great'>XML Parsing Tools</category>
// <developedBy>Apache Software Foundation</developedBy>
// </company>
DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(X("Core"));
if (impl != NULL)
{
try
{
DOMDocument* doc = impl->createDocument(
0, // root element namespace URI.
X("company"), // root element name
0); // document type object (DTD).
DOMElement* rootElem = doc->getDocumentElement();
DOMElement* prodElem = doc->createElement(X("product"));
rootElem->appendChild(prodElem);
DOMText* prodDataVal = doc->createTextNode(X("Xerces-C"));
prodElem->appendChild(prodDataVal);
DOMElement* catElem = doc->createElement(X("category"));
rootElem->appendChild(catElem);
catElem->setAttribute(X("idea"), X("great"));
DOMText* catDataVal = doc->createTextNode(X("XML Parsing Tools"));
catElem->appendChild(catDataVal);
DOMElement* devByElem = doc->createElement(X("developedBy"));
rootElem->appendChild(devByElem);
DOMText* devByDataVal = doc->createTextNode(X("Apache Software Foundation"));
devByElem->appendChild(devByDataVal);
//
// Now count the number of elements in the above DOM tree.
//
const XMLSize_t elementCount = doc->getElementsByTagName(X("*"))->getLength();
XERCES_STD_QUALIFIER cout << "The tree just created contains: " << elementCount
<< " elements." << XERCES_STD_QUALIFIER endl;
doc->release();
}
catch (const OutOfMemoryException&)
{
XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
errorCode = 5;
}
catch (const DOMException& e)
{
XERCES_STD_QUALIFIER cerr << "DOMException code is: " << e.code << XERCES_STD_QUALIFIER endl;
errorCode = 2;
}
catch (...)
{
//.........这里部分代码省略.........
示例13: writeHtmlFile
void writeHtmlFile(Tag2Html::MP3Collection* mp3Collection)
{
XMLPlatformUtils::Initialize();
DOMImplementation* domImplementation = DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("core"));
// <html>
DOMDocument* doc = domImplementation->createDocument(0, XMLString::transcode("html"), 0);
DOMDocumentType* docType = domImplementation->createDocumentType(XMLString::transcode("html"), XMLString::transcode(""), XMLString::transcode(""));
doc->insertBefore(docType, doc->getDocumentElement());
// <head>
DOMElement* head = doc->createElement(XMLString::transcode("head"));
// <link rel="stylesheet" type="text/css" href="./index.css">
DOMElement* linkStylesheet = doc->createElement(XMLString::transcode("link"));
linkStylesheet->setAttribute(XMLString::transcode("rel"), XMLString::transcode("stylesheet"));
linkStylesheet->setAttribute(XMLString::transcode("type"), XMLString::transcode("text/css"));
linkStylesheet->setAttribute(XMLString::transcode("href"), XMLString::transcode("index.css"));
head->appendChild(linkStylesheet);
// <title>MP3-Leser</title>
DOMElement* title = doc->createElement(XMLString::transcode("title"));
title->setTextContent(XMLString::transcode("MP3-Leser"));
head->appendChild(title);
// <meta http-equiv="Content-Type" content="text/html" charset="utf-8">
DOMElement* meta = doc->createElement(XMLString::transcode("meta"));
meta->setAttribute(XMLString::transcode("http-equiv"), XMLString::transcode("Content-Type"));
meta->setAttribute(XMLString::transcode("content"), XMLString::transcode("text/html"));
meta->setAttribute(XMLString::transcode("charset"), XMLString::transcode("utf-8"));
head->appendChild(meta);
// <body>
DOMElement* body = doc->createElement(XMLString::transcode("body"));
// <h1>
DOMElement* h1 = doc->createElement(XMLString::transcode("h1"));
// Track List ( view <a href="stats.html">stats</a>, <a href="info.html">info</a> )
h1->appendChild(doc->createTextNode(XMLString::transcode("Track List ( view ")));
DOMElement* statsLink = doc->createElement(XMLString::transcode("a"));
statsLink->setAttribute(XMLString::transcode("href"), XMLString::transcode("stats.html"));
statsLink->setTextContent(XMLString::transcode("stats"));
h1->appendChild(statsLink);
h1->appendChild(doc->createTextNode(XMLString::transcode(", ")));
DOMElement* infoLink = doc->createElement(XMLString::transcode("a"));
infoLink->setAttribute(XMLString::transcode("href"), XMLString::transcode("info.html"));
infoLink->setTextContent(XMLString::transcode("info"));
h1->appendChild(infoLink);
h1->appendChild(doc->createTextNode(XMLString::transcode(" )")));
body->appendChild(h1);
// <table align="center" width="1000">
DOMElement* table = doc->createElement(XMLString::transcode("table"));
table->setAttribute(XMLString::transcode("align"), XMLString::transcode("center"));
// <thead>
DOMElement* tHead = doc->createElement(XMLString::transcode("thead"));
// <tr bgcolor="#CCCCCC">
DOMElement* tHeadRow = doc->createElement(XMLString::transcode("tr"));
tHeadRow->setAttribute(XMLString::transcode("bgcolor"), XMLString::transcode("#CCCCCC"));
// <th>Track</th>
DOMElement* tHeadColumnTrack = doc->createElement(XMLString::transcode("th"));
tHeadColumnTrack->setTextContent(XMLString::transcode("Track"));
tHeadRow->appendChild(tHeadColumnTrack);
// <th>Artist</th>
DOMElement* tHeadColumnArtist = doc->createElement(XMLString::transcode("th"));
tHeadColumnArtist->setTextContent(XMLString::transcode("Artist"));
tHeadRow->appendChild(tHeadColumnArtist);
// <th>Title</th>
DOMElement* tHeadColumnTitle = doc->createElement(XMLString::transcode("th"));
tHeadColumnTitle->setTextContent(XMLString::transcode("Title"));
tHeadRow->appendChild(tHeadColumnTitle);
// <th>Album</th>
DOMElement* tHeadColumnAlbum = doc->createElement(XMLString::transcode("th"));
tHeadColumnAlbum->setTextContent(XMLString::transcode("Album"));
tHeadRow->appendChild(tHeadColumnAlbum);
// <th>Year</th>
DOMElement* tHeadColumnYear = doc->createElement(XMLString::transcode("th"));
tHeadColumnYear->setTextContent(XMLString::transcode("Year"));
tHeadRow->appendChild(tHeadColumnYear);
// <th>Genre</th>
DOMElement* tHeadColumnGenre = doc->createElement(XMLString::transcode("th"));
tHeadColumnGenre->setTextContent(XMLString::transcode("Genre"));
tHeadRow->appendChild(tHeadColumnGenre);
// <th>Comment</th>
DOMElement* tHeadColumnComment = doc->createElement(XMLString::transcode("th"));
tHeadColumnComment->setTextContent(XMLString::transcode("Comment"));
tHeadRow->appendChild(tHeadColumnComment);
// <th>Length</th>
DOMElement* tHeadColumnLength = doc->createElement(XMLString::transcode("th"));
//.........这里部分代码省略.........
示例14: 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;
}
示例15: main
/**
* Main routine that utilizes Xercesc module to create a DOM object in memory
* and prints out the resultant DOM structure
* @param argC number of command line args
* @param argV name of command line args
* @return 0 if no errors occurred
*/
int main(int argC, char*argv[]) {
// Initialize the XML4C2 system.
try {
XMLPlatformUtils::Initialize();
} catch (const XMLException& toCatch) {
char *pMsg = XMLString::transcode(toCatch.getMessage());
XERCES_STD_QUALIFIER cerr << "Error during Xerces-c Initialization.\n" << " Exception message:" << pMsg;
XMLString::release(&pMsg);
return 1;
}
// Watch for special case help request
int errorCode = 0;
if (argC > 1) {
XERCES_STD_QUALIFIER
cout << "\nUsage:\n"
" CreateDOMDocument\n\n"
"This program creates a new DOM document from scratch in memory.\n"
"It then prints the count of elements in the tree.\n" << XERCES_STD_QUALIFIER
endl;
errorCode = 1;
}
if (errorCode) {
XMLPlatformUtils::Terminate();
return errorCode;
}
DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(X("Core"));
if (impl != NULL) {
try {
// create a DomDocument instance
DOMDocument* doc = impl->createDocument(
0, // root element namespace URI.
X("TheHood"), // root element name
0); // document type object (DTD).
// create root attribute nodes
DOMAttr* woop_atr = doc->createAttribute(X("WOOP"));
woop_atr->setValue(X("DANG"));
DOMAttr* fiyah_atr = doc->createAttribute(X("FIYAH"));
fiyah_atr->setValue(X("hot"));
DOMAttr* hungry_atr = doc->createAttribute(X("hungry"));
hungry_atr->setValue(X("starving"));
// create root element
DOMElement* rootElem = doc->getDocumentElement();
// set root attrs
rootElem->setAttributeNode(woop_atr);
rootElem->setAttributeNode(fiyah_atr);
rootElem->setAttributeNode(hungry_atr);
//create root child elements
DOMElement* gangElem = doc->createElement(X("gang"));
rootElem->appendChild(gangElem);
DOMText* gangDataVal = doc->createTextNode(X("YoungThugz"));
gangElem->appendChild(gangDataVal);
gangElem->setAttribute(X("hardness"), X("rock"));
//create gang attr nodes
DOMAttr* members_atr = doc->createAttribute(X("members"));
members_atr->setValue(X("500"));
DOMAttr* color_atr = doc->createAttribute(X("color"));
color_atr->setValue(X("magenta"));
// set gang attr
gangElem->setAttributeNode(members_atr);
gangElem->setAttributeNode(color_atr);
// create gang elem children
DOMElement* piruElem = doc->createElement(X("piru"));
piruElem->setNodeValue(X("w"));
DOMElement* cripElem = doc->createElement(X("crip"));
cripElem->setNodeValue(X("t"));
DOMElement* trgElem = doc->createElement(X("trg"));
trgElem->setNodeValue(X("o"));
// append gang elem children
gangElem->appendChild(piruElem);
gangElem->appendChild(cripElem);
gangElem->appendChild(trgElem);
DOMElement* turfElem = doc->createElement(X("turf"));
rootElem->appendChild(turfElem);
turfElem->setAttribute(X("idea"), X("great"));
DOMText* turfDataVal = doc->createTextNode(X("West Side Projects"));
turfElem->appendChild(turfDataVal);
DOMElement* cliqueElem = doc->createElement(X("clique"));
rootElem->appendChild(cliqueElem);
DOMText* cliqueDataVal = doc->createTextNode(X("Balla$"));
cliqueElem->appendChild(cliqueDataVal);
cliqueElem->setAttribute(X("Comradery"), X("tight"));
DOMElement* sideElem = doc->createElement(X("side"));
//.........这里部分代码省略.........