本文整理汇总了C++中DOMDocument::createAttribute方法的典型用法代码示例。如果您正苦于以下问题:C++ DOMDocument::createAttribute方法的具体用法?C++ DOMDocument::createAttribute怎么用?C++ DOMDocument::createAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMDocument
的用法示例。
在下文中一共展示了DOMDocument::createAttribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
//.........这里部分代码省略.........
示例2: 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"));
//.........这里部分代码省略.........