本文整理汇总了C++中DOMLSSerializer::setNewLine方法的典型用法代码示例。如果您正苦于以下问题:C++ DOMLSSerializer::setNewLine方法的具体用法?C++ DOMLSSerializer::setNewLine怎么用?C++ DOMLSSerializer::setNewLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMLSSerializer
的用法示例。
在下文中一共展示了DOMLSSerializer::setNewLine方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: transcode
string tsp::Tool::xmlNode2String(const DOMNode* node) {
if (!initXmlEngine())
return NULL;
DOMImplementation *implementation =
DOMImplementationRegistry::getDOMImplementation(
XMLString::transcode("LS"));
// Create a DOMLSSerializer which is used to serialize a DOM tree into an XML document.
DOMLSSerializer *serializer =
((DOMImplementationLS*) implementation)->createLSSerializer();
// Make the output more human readable by inserting line feeds.
if (serializer->getDomConfig()->canSetParameter(
XMLUni::fgDOMWRTFormatPrettyPrint, true))
serializer->getDomConfig()->setParameter(
XMLUni::fgDOMWRTFormatPrettyPrint, true);
// The end-of-line sequence of characters to be used in the XML being written out.
serializer->setNewLine(XMLString::transcode("\r\n"));
return XMLString::transcode(serializer->writeToString(node));
}
示例2: OutputXML
void OutputXML(xercesc::DOMDocument* pmyDOMDocument, std::string filePath)
{
//Return the first registered implementation that has the desired features. In this case, we are after a DOM implementation that has the LS feature... or Load/Save.
DOMImplementation *implementation = DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("LS"));
// Create a DOMLSSerializer which is used to serialize a DOM tree into an XML document.
DOMLSSerializer *serializer = ((DOMImplementationLS*)implementation)->createLSSerializer();
// Make the output more human readable by inserting line feeds.
if (serializer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
serializer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
// The end-of-line sequence of characters to be used in the XML being written out.
serializer->setNewLine(XMLString::transcode("\r\n"));
// Convert the path into Xerces compatible XMLCh*.
XMLCh *tempFilePath = XMLString::transcode(filePath.c_str());
// Specify the target for the XML output.
XMLFormatTarget *formatTarget = new LocalFileFormatTarget(tempFilePath);
// Create a new empty output destination object.
DOMLSOutput *output = ((DOMImplementationLS*)implementation)->createLSOutput();
// Set the stream to our target.
output->setByteStream(formatTarget);
// Write the serialized output to the destination.
serializer->write(pmyDOMDocument, output);
// Cleanup.
serializer->release();
XMLString::release(&tempFilePath);
delete formatTarget;
output->release();
}
示例3: main
//.........这里部分代码省略.........
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;
}
}
示例4: SaveDocument
void ParameterManager::SaveDocument(XMLFormatTarget* pFormatTarget) const
{
#if (XERCES_VERSION_MAJOR == 2)
DOMPrintFilter *myFilter = 0;
try {
// get a serializer, an instance of DOMWriter
XMLCh tempStr[100];
XMLString::transcode("LS", tempStr, 99);
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
DOMWriter *theSerializer = ((DOMImplementationLS*)impl)->createDOMWriter();
// set user specified end of line sequence and output encoding
theSerializer->setNewLine(gMyEOLSequence);
theSerializer->setEncoding(gOutputEncoding);
// plug in user's own filter
if (gUseFilter) {
// even we say to show attribute, but the DOMWriter
// will not show attribute nodes to the filter as
// the specs explicitly says that DOMWriter shall
// NOT show attributes to DOMWriterFilter.
//
// so DOMNodeFilter::SHOW_ATTRIBUTE has no effect.
// same DOMNodeFilter::SHOW_DOCUMENT_TYPE, no effect.
//
myFilter = new DOMPrintFilter(DOMNodeFilter::SHOW_ELEMENT |
DOMNodeFilter::SHOW_ATTRIBUTE |
DOMNodeFilter::SHOW_DOCUMENT_TYPE
);
theSerializer->setFilter(myFilter);
}
// plug in user's own error handler
DOMErrorHandler *myErrorHandler = new DOMPrintErrorHandler();
theSerializer->setErrorHandler(myErrorHandler);
// set feature if the serializer supports the feature/mode
if (theSerializer->canSetFeature(XMLUni::fgDOMWRTSplitCdataSections, gSplitCdataSections))
theSerializer->setFeature(XMLUni::fgDOMWRTSplitCdataSections, gSplitCdataSections);
if (theSerializer->canSetFeature(XMLUni::fgDOMWRTDiscardDefaultContent, gDiscardDefaultContent))
theSerializer->setFeature(XMLUni::fgDOMWRTDiscardDefaultContent, gDiscardDefaultContent);
if (theSerializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, gFormatPrettyPrint))
theSerializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, gFormatPrettyPrint);
//
// do the serialization through DOMWriter::writeNode();
//
theSerializer->writeNode(pFormatTarget, *_pDocument);
delete theSerializer;
//
// Filter and error handler
// are NOT owned by the serializer.
//
delete myErrorHandler;
if (gUseFilter)
delete myFilter;
}
catch (XMLException& e) {
std::cerr << "An error occurred during creation of output transcoder. Msg is:"
<< std::endl
<< StrX(e.getMessage()) << std::endl;
}
#else
try {
// get a serializer, an instance of DOMWriter
XMLCh tempStr[100];
XMLString::transcode("LS", tempStr, 99);
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
DOMLSSerializer *theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
// set user specified end of line sequence and output encoding
theSerializer->setNewLine(gMyEOLSequence);
DOMConfiguration* config = theSerializer->getDomConfig();
config->setParameter(XStr("format-pretty-print").unicodeForm(),true);
//
// do the serialization through DOMWriter::writeNode();
//
DOMLSOutput *theOutput = ((DOMImplementationLS*)impl)->createLSOutput();
theOutput->setEncoding(gOutputEncoding);
theOutput->setByteStream(pFormatTarget);
theSerializer->write(_pDocument, theOutput);
delete theSerializer;
}
catch (XMLException& e) {
std::cerr << "An error occurred during creation of output transcoder. Msg is:"
<< std::endl
<< StrX(e.getMessage()) << std::endl;
}
#endif
}