DOMElement* EppCommandInfoLaunchRegistration::toXML( DOMDocument& doc, const DOMString& tag ) { DOMElement* elm; DOMElement* body = EppUtil::createElementNS(doc, "launch", (tag.isNull()) ? "info" : tag, false, "-1.0"); DOMAttr* attr = doc.createAttribute(XS("includeMark")); attr->setValue( ( this->_includeMark ) ? XS("true") : XS("false") ); body->setAttributeNode(attr); if( this->_phase.phase().length() > 0 ) { DOMElement* elm = this->_phase.toXML(doc, "phase"); body->appendChild(elm); } if( this->_appId.isNotNull() ) { if( this->_appId.length() > 0 ) { elm = doc.createElement(XS("applicationID")); elm->appendChild(doc.createTextNode(this->_appId)); body->appendChild(elm); } } return body; }
DOMElement* EppCommandCreateLaunchRegistration::toXML( DOMDocument& doc, const DOMString& tag ) { DOMElement* elm; DOMElement* body = EppUtil::createElementNS(doc, "launch", (tag.isNull()) ? "create" : tag, false, "-1.0"); if( this->_type.length() > 0 ) { DOMAttr* attr = doc.createAttribute(XS("type")); attr->setValue( this->_type); body->setAttributeNode(attr); } if ( this->_phase.phase().length() > 0 ) { DOMElement* elm = this->_phase.toXML(doc, "phase"); body->appendChild(elm); } if( (_signedMark.hasSMD()) ) { /*RAII*/ DOMElement* elm = this->_signedMark.toXML(doc, "signedMark"); body->appendChild(elm); } if( (_encSignedMark.hasSMD()) ) { /*RAII*/ DOMElement* elm = this->_encSignedMark.toXML(doc, "encodedSignedMark"); body->appendChild(elm); } if( this->_noticeID.length() > 0 ) { elm = doc.createElement(XS("noticeID")); elm->appendChild(doc.createTextNode(this->_noticeID)); body->appendChild(elm); } if( this->_notAfter.length() > 0 ) { elm = doc.createElement(XS("notAfter")); elm->appendChild(doc.createTextNode(this->_notAfter)); body->appendChild(elm); } if( this->_acceptedDate.length() > 0 ) { elm = doc.createElement(XS("acceptedDate")); elm->appendChild(doc.createTextNode(this->_acceptedDate)); body->appendChild(elm); } return body; }
DOMElement* EppLaunchPhase::toXML(DOMDocument &doc, const DOMString &tag) { //DOMElement* elm; DOMElement* body = doc.createElement(tag); if( this->_sub_phase.length() > 0 ) { DOMAttr* attr = doc.createAttribute(XS("name")); attr->setValue( this->_sub_phase ); body->setAttributeNode(attr); } if( this->_phase.length() > 0 ) { body->appendChild(doc.createTextNode(this->_phase)); } return body; }
void XercesUpdateFactory::applyReplaceAttribute(const PendingUpdate &update, DynamicContext *context) { const XercesNodeImpl *nodeImpl = (const XercesNodeImpl*)update.getTarget()->getInterface(Item::gXQilla); DOMAttr *domnode = (DOMAttr*)nodeImpl->getDOMNode(); Node::Ptr parentNode = nodeImpl->dmParent(context); DOMElement *element = domnode->getOwnerElement(); DOMDocument *doc = element->getOwnerDocument(); bool untyped = parentNode->dmNodeKind() == Node::element_string && XPath2Utils::equals(parentNode->getTypeName(), DocumentCache::g_szUntyped) && XPath2Utils::equals(parentNode->getTypeURI(), SchemaSymbols::fgURI_SCHEMAFORSCHEMA); Result children = update.getValue(); Item::Ptr item; while((item = children->next(context)).notNull()) { const XercesNodeImpl *childImpl = (const XercesNodeImpl*)item->getInterface(Item::gXQilla); DOMNode *newChild = importNodeFix(doc, const_cast<DOMNode*>(childImpl->getDOMNode()), /*deep*/true); // 1. Error checks: // a. If the QNames of any two attribute nodes in $replacement have implied namespace bindings that conflict with // each other, a dynamic error is raised [err:XUDY0024]. // b. If the QName of any attribute node in $replacement has an implied namespace binding that conflicts with a // namespace binding in the "namespaces" property of parent($target), a dynamic error is raised [err:XUDY0024]. // Checks performed by UpdateFactory // 2b. If the type-name property of parent($target) is xs:untyped, then upd:setToUntyped() is invoked // on each element node in $replacement. if(!untyped) setTypes(newChild, childImpl->getDOMNode()); // 2a. For each node in $replacement, the parent property is set to parent($target). // 4a. If $target is an attribute node, the attributes property of parent($target) is modified by removing $target // and adding the nodes in $replacement (if any). // 4b. If $target is an attribute node, the namespaces property of parent($target) is modified to include namespace // bindings for any attribute namespace prefixes in $replacement that did not already have bindings. element->setAttributeNode((DOMAttr*)newChild); } // 3a. $target is marked for deletion. forDeletion_.insert(domnode); // 4d. upd:removeType(parent($target)) is invoked. removeType(element); // Use parentNode, since the attr replace could have removed the original attr addToPutSet(parentNode, &update, context); }
/* NOTE: need to keep _type field in consideration as attribute type/entitlement depends on it.*/ DOMElement* EppMarkHolder::toXML(DOMDocument &doc, const DOMString &tag) { DOMString attr_name = "type"; DOMElement* elm; DOMElement* body = doc.createElement(tag); if( this->_type == EPPMARK_HOLDER ) { attr_name = "entitlement"; } DOMAttr* attr = doc.createAttribute(attr_name); attr->setValue( this->_addParam ); body->setAttributeNode(attr); if( this->_name.length() > 0 ) { elm = doc.createElement(XS("name")); elm->appendChild(doc.createTextNode(this->_name)); body->appendChild(elm); } if( this->_org.length() > 0 ) { elm = doc.createElement(XS("org")); elm->appendChild(doc.createTextNode(this->_org)); body->appendChild(elm); } body->appendChild(this->_addr.toXML(doc, "addr")); if( this->_voice.getNumber().length() > 0 ) { elm = this->_voice.toXML(doc, "voice"); body->appendChild(elm); } if( this->_fax.getNumber().length() > 0 ) { elm = this->_fax.toXML(doc, "fax"); body->appendChild(elm); } if( this->_email.length() > 0 ) { elm = doc.createElement(XS("email")); elm->appendChild(doc.createTextNode(this->_email)); body->appendChild(elm); } return body; }
DOMNode* DOMAttrImpl::rename(const XMLCh* namespaceURI, const XMLCh* name) { DOMElement* el = getOwnerElement(); DOMDocumentImpl* doc = (DOMDocumentImpl*)fParent.fOwnerDocument; if (el) el->removeAttributeNode(this); if (!namespaceURI || !*namespaceURI) { fName = doc->getPooledString(name); if (el) el->setAttributeNode(this); // and fire user data NODE_RENAMED event castToNodeImpl(this)->callUserDataHandlers(DOMUserDataHandler::NODE_RENAMED, this, this); return this; } else { // create a new AttrNS DOMAttr* newAttr = doc->createAttributeNS(namespaceURI, name); // transfer the userData doc->transferUserData(castToNodeImpl(this), castToNodeImpl(newAttr)); // move children to new node DOMNode* child = getFirstChild(); while (child) { removeChild(child); newAttr->appendChild(child); child = getFirstChild(); } // reattach attr to element if (el) el->setAttributeNodeNS(newAttr); // and fire user data NODE_RENAMED event castToNodeImpl(newAttr)->callUserDataHandlers(DOMUserDataHandler::NODE_RENAMED, this, newAttr); return newAttr; } }
void XercesUpdateFactory::applyInsertAttributes(const PendingUpdate &update, DynamicContext *context) { const XercesNodeImpl *nodeImpl = (const XercesNodeImpl*)update.getTarget()->getInterface(Item::gXQilla); DOMElement *element = (DOMElement*)nodeImpl->getDOMNode(); DOMDocument *doc = const_cast<DOMDocument*>(XPath2Utils::getOwnerDoc(element)); bool untyped = nodeImpl->dmNodeKind() == Node::element_string && XPath2Utils::equals(nodeImpl->getTypeName(), DocumentCache::g_szUntyped) && XPath2Utils::equals(nodeImpl->getTypeURI(), SchemaSymbols::fgURI_SCHEMAFORSCHEMA); Result children = update.getValue(); Item::Ptr item; while((item = children->next(context)).notNull()) { const XercesNodeImpl *childImpl = (const XercesNodeImpl*)item->getInterface(Item::gXQilla); DOMNode *newChild = importNodeFix(doc, const_cast<DOMNode*>(childImpl->getDOMNode()), /*deep*/true); // 1. Error checks: // a. If the QNames of any two attribute nodes in $content have implied namespace bindings that conflict with each other, // a dynamic error is raised [err:XUDY0024]. // b. If the QName of any attribute node in $content has an implied namespace binding that conflicts with a namespace // binding in the "namespaces" property of $target, a dynamic error is raised [err:XUDY0024]. // Checks performed by UpdateFactory // If the type-name property of $target is xs:untyped, then upd:setToUntyped($A) is invoked. if(!untyped) setTypes(newChild, childImpl->getDOMNode()); // The parent property of $A is set to $target. // attributes: Modified to include the nodes in $content. element->setAttributeNode((DOMAttr*)newChild); } // upd:removeType($target) is invoked. removeType(element); addToPutSet(update.getTarget(), &update, context); }
DOMElement* EppCommand::toXMLCommon( DOMDocument& doc, const DOMString command, DOMElement* element, EppEntity * object, const DOMString tag, ValueVectorOf<DOMAttr*> * attrList ) { DOMElement* elm = null; DOMElement* epp = EppUtil::createElementNS(doc, "epp", NULLXS); DOMElement* body = doc.createElement(XS("command")); epp->appendChild(body); //if( creds != null ) //{ // body->appendChild(creds->toXML(doc, "creds")); //} if( this->getEntityType() == EppEntity::TYPE_EppCommandLogin ) { elm = element; } else { elm = doc.createElement(command); } if( elm != null ) { if( attrList != null ) { for( unsigned int i = 0; i < attrList->size(); i++ ) { DOMAttr* obj = attrList->elementAt(i); elm->setAttributeNode(obj); } } if( object != null ) { elm->appendChild(object->toXML(doc, tag)); } else if( element != null ) { if( this->getEntityType() != EppEntity::TYPE_EppCommandLogin ) { elm->appendChild(element); } } body->appendChild(elm); } if( extension != null ) { elm = null; for( unsigned int i = 0; i < extension->size(); i++ ) { EppEntity * obj = extension->elementAt(i); DOMElement* ext; if( obj == null ) { continue; } if( obj->getEntityType() == EppEntity::TYPE_EppExtensionUnspec ) { EppUnspec * unspec = (EppUnspec *) obj; ext = unspec->toXML(doc, "extension"); } else if( obj->instanceOf(EppEntity::TYPE_EppExtension) == true ) { EppExtension * extobj = (EppExtension *) obj; ext = extobj->toXML(doc, NULLXS); } else { ext = obj->toXML(doc, "extension"); } if( ext != null ) { if( elm == null ) { elm = doc.createElement(XS("extension")); body->appendChild(elm); } elm->appendChild(ext); } } } if( clTRID.isNotNull() ) { elm = doc.createElement(XS("clTRID")); elm->appendChild(doc.createTextNode(clTRID)); body->appendChild(elm); } return epp; }
/** * 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")); rootElem->appendChild(sideElem); DOMText* sideDataVal = doc->createTextNode(X("North North")); sideElem->appendChild(sideDataVal); // create side elem children DOMElement* tempElem = doc->createElement(X("temperature")); tempElem->setNodeValue(X("100 C")); DOMElement* med_incomeElem = doc->createElement(X("medianIncome")); med_incomeElem->setNodeValue(X("$20,000")); DOMElement* schoolsElem = doc->createElement(X("schools")); schoolsElem->setNodeValue(X("Regional")); // append side elem children sideElem->appendChild(tempElem); sideElem->appendChild(med_incomeElem); sideElem->appendChild(schoolsElem); DOMElement* gatElem = doc->createElement(X("gat")); rootElem->appendChild(gatElem); DOMText* gatDataVal = doc->createTextNode(X("Glock")); gatElem->appendChild(gatDataVal); //set gat attr gatElem->setAttribute(X("caliber"), X(".50")); // create gat elem children DOMElement* rifleElem = doc->createElement(X("rifle")); DOMElement* meleeElem = doc->createElement(X("melee")); DOMElement* pieceElem = doc->createElement(X("piece")); // append gat elem children gatElem->appendChild(rifleElem); gatElem->appendChild(meleeElem); gatElem->appendChild(pieceElem); DOMElement* contraElem = doc->createElement(X("contra")); rootElem->appendChild(contraElem); DOMText* contraDataVal = doc->createTextNode(X("Cocoa")); contraElem->appendChild(contraDataVal); contraElem->setAttribute(X("rareness"), X("extreme")); // create contra elem children DOMElement* methElem = doc->createElement(X("meth")); DOMElement* ganjaElem = doc->createElement(X("ganja")); DOMElement* ethElem = doc->createElement(X("ethanol")); // append contra elem children contraElem->appendChild(methElem); contraElem->appendChild(ganjaElem); contraElem->appendChild(ethElem); //create contra attr nodes DOMAttr* price_atr = doc->createAttribute(X("price")); price_atr->setValue(X("$25")); DOMAttr* source_atr = doc->createAttribute(X("source")); source_atr->setValue(X("Columbia")); // set contra attr contraElem->setAttributeNode(price_atr); contraElem->setAttributeNode(source_atr); DOMElement* rivalsElem = doc->createElement(X("rivals")); rootElem->appendChild(rivalsElem); DOMText* rivalsDataVal = doc->createTextNode(X("Warrriors")); rivalsElem->appendChild(rivalsDataVal); DOMElement* policeElem = doc->createElement(X("police")); rootElem->appendChild(policeElem); DOMText* policeDataVal = doc->createTextNode(X("popo")); policeElem->appendChild(policeDataVal); DOMElement* drugsElem = doc->createElement(X("drugs")); rootElem->appendChild(drugsElem); DOMText* drugsDataVal = doc->createTextNode(X("codiene")); drugsElem->appendChild(drugsDataVal); // create drugs elem children DOMElement* mixElem = doc->createElement(X("mix")); DOMElement* spriteElem = doc->createElement(X("sprite")); DOMElement* leanElem = doc->createElement(X("lean")); // append drugs elem children drugsElem->appendChild(mixElem); drugsElem->appendChild(spriteElem); drugsElem->appendChild(leanElem); DOMElement* crimeElem = doc->createElement(X("crime")); rootElem->appendChild(crimeElem); DOMText* crimeDataVal = doc->createTextNode(X("187")); crimeElem->appendChild(crimeDataVal); // // 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; // create serializer instance DOMLSSerializer *theSerializer = ((DOMImplementationLS*) impl)->createLSSerializer(); // create output instance DOMLSOutput *theOutputDesc = ((DOMImplementationLS*) impl)->createLSOutput(); // referenced the following http://stackoverflow.com/questions/2897317/writing-xml-with-xerces-3-0-1-and-c-on-windows // set output from serializer to stdout XMLFormatTarget *myFormTarget; myFormTarget = new StdOutFormatTarget(); theOutputDesc->setByteStream(myFormTarget); // Make the output more human readable by inserting line feeds. if (theSerializer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true)) theSerializer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true); // The end-of-line sequence of characters to be used in the XML being written out. theSerializer->setNewLine(XMLString::transcode("\r\n")); // output the DOM theSerializer->write(doc, theOutputDesc); cout << endl << endl << "*****************************************" << endl; // Using DOMTreeWalker class to traverse tree // create tree walker DOMTreeWalker* walker = doc->createTreeWalker(rootElem, DOMNodeFilter::SHOW_ELEMENT, NULL, true); // create vector to hold Dom nodes vector<DOMNode*> elem_vec; // traverse tree using walker for (DOMNode* current = walker->nextNode(); current != 0; current = walker->nextNode()) { // store nodes int vector elem_vec.push_back(current); } // sort function - alphabetically elements std::sort(elem_vec.begin(), elem_vec.end(), compare_elem_alpha); // iterate through sorted nodes for (auto i : elem_vec) { int x; string text = string(x(i->getTextContent())); cout << "Node Name: " << x(i->getNodeName()) << ((text != "") ? " |Text Content: " + text : "") << endl; //get attr map if (i->hasAttributes()) { DOMNamedNodeMap *attr_map = i->getAttributes(); // get each node in the map for (x = 0; x < attr_map->getLength(); x++) { DOMNode *temp = attr_map->item(x); cout << setw(5) << "" << "Attribute" << x + 1 << ": " << x(temp->getNodeName()) << " = " << x(temp->getNodeValue()) << endl; } } } // release doc resources 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 (...) { XERCES_STD_QUALIFIER cerr << "An error occurred creating the document" << XERCES_STD_QUALIFIER endl; errorCode = 3; } }// (impl != NULL) else { XERCES_STD_QUALIFIER cerr << "Requested implementation is not supported" << XERCES_STD_QUALIFIER endl; errorCode = 4; } }