本文整理汇总了C++中DOMLSOutput::setByteStream方法的典型用法代码示例。如果您正苦于以下问题:C++ DOMLSOutput::setByteStream方法的具体用法?C++ DOMLSOutput::setByteStream怎么用?C++ DOMLSOutput::setByteStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMLSOutput
的用法示例。
在下文中一共展示了DOMLSOutput::setByteStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: domPrint
//
// domPrint - Dump the contents of a DOM node.
// For debugging failures, when all else fails.
// Works recursively - initially called with a document node.
//
void ThreadParser::domPrint()
{
printf("Begin DOMPrint ...\n");
if (gRunInfo.dom)
{
try
{
XMLCh tempStr[100];
XMLString::transcode("LS", tempStr, 99);
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
DOMLSSerializer *theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
DOMLSOutput *theOutput = ((DOMImplementationLS*)impl)->createLSOutput();
XMLFormatTarget *myFormTarget = new StdOutFormatTarget();
theOutput->setByteStream(myFormTarget);
DOMNode *doc = fXercesDOMParser->getDocument();
theSerializer->write(doc,theOutput);
delete myFormTarget;
theSerializer->release();
theOutput->release();
}
catch (...)
{
// do nothing
}
}
printf("End DOMPrint\n");
}
示例2: DomNodeToString
CStdString DomSerializer::DomNodeToString(DOMNode* node)
{
CStdString output;
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(XStr("LS").unicodeForm());
DOMLSSerializer *theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
DOMConfiguration * dc = theSerializer->getDomConfig();
// set user specified output encoding
//dc->setEncoding(gOutputEncoding);
dc->setParameter(XStr("format-pretty-print").unicodeForm(), true);
XMLFormatTarget *myFormTarget;
myFormTarget = new MemBufFormatTarget ();
DOMLSOutput *outputStream = ((DOMImplementationLS*)impl)->createLSOutput();
outputStream->setByteStream(myFormTarget);
theSerializer->write(node, outputStream);
output = (char *)((MemBufFormatTarget*)myFormTarget)->getRawBuffer();
// Clean up
delete theSerializer;
//
// Filter, formatTarget and error handler
// are NOT owned by the serializer.
delete myFormTarget;
return output;
}
示例3: serialize
void serializer::serialize(EObject_ptr obj)
{
m_root_obj = obj;
m_impl = DOMImplementationRegistry::getDOMImplementation(X("Core"));
if (m_impl)
{
EClass_ptr cl = obj->eClass();
EPackage_ptr pkg = cl->getEPackage();
::ecorecpp::mapping::type_traits::string_t const& ns_uri = pkg->getNsURI();
m_doc = m_impl->createDocument(
(ns_uri.empty()) ? X("NULL") : W(ns_uri), // root element namespace URI.
W(get_type(obj)), // root element name
0); // document type object (DTD)
m_root = m_doc->getDocumentElement();
// common attributes
// xmlns:xmi="http://www.omg.org/XMI"
m_root->setAttribute(X("xmlns:xmi"), X("http://www.omg.org/XMI"));
// xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
m_root->setAttribute(X("xmlns:xsi"),
X("http://www.w3.org/2001/XMLSchema-instance"));
// xmi:version="2.0"
m_root->setAttribute(X("xmi:version"), X("2.0"));
serialize_node(m_root, obj);
// write
// TODO: outta here
DOMLSSerializer *theSerializer =
((DOMImplementationLS*) m_impl)->createLSSerializer();
DOMLSOutput *theOutputDesc =
((DOMImplementationLS*) m_impl)->createLSOutput();
DOMConfiguration* serializerConfig = theSerializer->getDomConfig();
// TODO: set as option
if (serializerConfig->canSetParameter(
XMLUni::fgDOMWRTFormatPrettyPrint, true))
serializerConfig->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint,
true);
XMLFormatTarget *myFormTarget;
myFormTarget = new LocalFileFormatTarget(X(m_file));
theOutputDesc->setByteStream(myFormTarget);
theSerializer->write(m_doc, theOutputDesc);
theOutputDesc->release();
theSerializer->release();
delete myFormTarget;
}
else
throw "Error";
}
示例4: Write
/* Write the file. */
bool GQCFileData::Write(const std::string &fileName)
{
// Initialize the XML4C2 system.
try
{
XMLPlatformUtils::Initialize();
}
catch (const XMLException&)
{
return false;
}
// Create a DOM implementation object and create the document type for it.
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(ToXMLCh(L"LS"));
DOMDocument* doc = impl->createDocument();
//doc->setStandalone(true);
// Create the serializer.
DOMLSSerializer *theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
DOMLSOutput *theOutputDesc = ((DOMImplementationLS*)impl)->createLSOutput();
//theSerializer->setEncoding(ToXMLCh(GENERIC_REPORT_FILE_ENCODING));
theOutputDesc->setEncoding(ToXMLCh(GENERIC_REPORT_FILE_ENCODING));
// Create the root element
DOMElement *rootElement = CreateGenericReportElement(doc);
// store the parameters
AddNameValuePairs(ANALYSIS_PARAMETERS, analysisParameters, doc, rootElement);
AddNameValuePairs(QC_RESULTS, qcResults, doc, rootElement);
AddNameValuePairs(SAMPLE_SIGNATURE, sampleSignature, doc, rootElement);
// Add an empty table (required by the DTD)
AddBlankReportTable(doc, rootElement);
// Store the element to the document.
doc->appendChild(rootElement);
// Write the file.
bool status = false;
XMLFormatTarget *myFormTarget = new LocalFileFormatTarget(fileName.c_str());
theOutputDesc->setByteStream(myFormTarget);
try
{
theSerializer->write(doc, theOutputDesc);
status = true;
}
catch (...)
{
status = false;
}
// Clean up
doc->release();
theOutputDesc->release();
theSerializer->release();
delete myFormTarget;
XMLPlatformUtils::Terminate();
return status;
}
示例5: WriteEntity
void EntityXMLFileWriter::WriteEntity(World* world, EntityID entity)
{
using namespace xercesc;
DOMDocument* doc = m_DOMImplementation->createDocument(nullptr, X("Entity"), nullptr);
DOMElement* root = doc->getDocumentElement();
root->setAttribute(X("xmlns:xsi"), X("http://www.w3.org/2001/XMLSchema-instance"));
root->setAttribute(X("xsi:noNamespaceSchemaLocation"), X("../Types/Entity.xsd"));
root->setAttribute(X("xmlns:c"), X("components"));
const std::string& name = world->GetName(entity);
if (!name.empty()) {
root->setAttribute(X("name"), X(name));
}
DOMElement* componentsElement = doc->createElement(X("Components"));
root->appendChild(componentsElement);
appentEntityComponents(componentsElement, world, entity);
DOMElement* childrenElement = doc->createElement(X("Children"));
root->appendChild(childrenElement);
appendEntityChildren(childrenElement, world, entity);
try {
LocalFileFormatTarget* target = new LocalFileFormatTarget(X(m_FilePath.string()));
DOMLSOutput* output = static_cast<DOMImplementationLS*>(m_DOMImplementation)->createLSOutput();
output->setByteStream(target);
m_DOMLSSerializer->write(doc, output);
delete target;
} catch (const std::runtime_error& e) {
LOG_ERROR("Failed to save \"%s\": %s", m_FilePath.c_str(), e.what());
}
doc->release();
}
示例6: SerializeXercesDocument
void SerializeXercesDocument(xercesc::DOMDocument& document, xercesc::XMLFormatTarget& target) {
// call into xerces for serialization
// cf. http://xerces.apache.org/xerces-c/program-dom-3.html#DOMLSSerializer
static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(gLS);
// construct the DOMWriter
DOMLSSerializer *writer = ((DOMImplementationLS*)impl)->createLSSerializer();
// optionally you can set some features on this serializer
if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTDiscardDefaultContent, true))
writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTDiscardDefaultContent, true);
if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
// prepare output
DOMLSOutput *outp = ((DOMImplementationLS*)impl)->createLSOutput();
outp->setByteStream(&target);
// serialize the DOMNode to a UTF-16 string
writer->write(&document, outp);
// release the memory
outp->release();
writer->release();
}
示例7: target
static void
serialise (DOMDocument const *doc, std::string const &output)
{
XMLCh const LS[] = { chLatin_L, chLatin_S, chNull };
DOMImplementationLS &impl = dynamic_cast<DOMImplementationLS &> (*DOMImplementationRegistry::getDOMImplementation (LS));
DOMLSSerializer *writer = impl.createLSSerializer ();
DOMLSOutput *desc = impl.createLSOutput ();
LocalFileFormatTarget target (output.c_str ());
desc->setByteStream (&target);
writer->write (doc, desc);
}
示例8: serializeDOM
bool serializeDOM(std::ostream& output, bool)
{
XMLCh tempStr[100];
XMLString::transcode("LS", tempStr, 99);
DOMImplementationLS *impl = dynamic_cast<DOMImplementationLS *>(DOMImplementationRegistry::getDOMImplementation(tempStr));
DOMLSSerializer *theSerializer = impl->createLSSerializer();
DOMLSOutput *theOutputDesc = impl->createLSOutput();
bool rc = false;
try
{
MemBufFormatTarget *myFormTarget = new MemBufFormatTarget();
/* do the serialization through DOMLSSerializer::write(); */
theOutputDesc->setByteStream(myFormTarget);
theSerializer->write(inputFileDOM, theOutputDesc);
const XMLByte * data = myFormTarget->getRawBuffer();
XMLSize_t len = myFormTarget->getLen();
output.write( reinterpret_cast<const char *>(data), len );
delete myFormTarget;
rc = true;
}
catch (IOException& e ) {
cerr << StrX(e.getMessage());
cerr << " Code is " << e.getCode();
if ( errno != 0 ) {
cerr << ": " << strerror( errno );
}
}
catch (XMLException& e)
{
cerr << "An error occurred during creation of output transcoder. Msg is:"
<< endl
<< StrX(e.getMessage());
if ( errno != 0 ) {
cerr << ": " << strerror( errno );
}
cerr << endl;
rc = false;
}
delete theSerializer;
return rc;
}
示例9: serializeXMLDocumentToFile
int ModelicaXML::serializeXMLDocumentToFile(mstring xmlFileName)
{
// fix the file
XMLFormatTarget *myFormatTarget = new LocalFileFormatTarget(X(xmlFileName.c_str()));
theOutputDesc->setByteStream(myFormatTarget);
// serialize a DOMNode to the local file "
domSerializer->write(pModelicaXMLDoc, theOutputDesc);
myFormatTarget->flush();
delete myFormatTarget;
return 0;
}
示例10: dumpTree
/// Dump DOM tree using XercesC handles
void dumpTree(DOMNode* doc, ostream& os) {
if ( doc ) {
DOMImplementation *imp = DOMImplementationRegistry::getDOMImplementation(Strng_t("LS"));
MemBufFormatTarget *tar = new MemBufFormatTarget();
DOMLSOutput *out = imp->createLSOutput();
DOMLSSerializer *wrt = imp->createLSSerializer();
out->setByteStream(tar);
wrt->getDomConfig()->setParameter(Strng_t("format-pretty-print"), true);
wrt->write(doc, out);
os << tar->getRawBuffer() << endl << flush;
out->release();
wrt->release();
return;
}
printout(ERROR,"dumpTree","+++ Cannot dump invalid document.");
}
示例11: serializeNode
void Normalizer::serializeNode(const DOMNode * const node) {
XMLCh tempStr[100];
XMLString::transcode("LS", tempStr, 99);
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
DOMLSSerializer *theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
DOMLSOutput *theOutput = ((DOMImplementationLS*)impl)->createLSOutput();
theSerializer->getDomConfig()->setParameter(X("format-pretty-print"), true);
XMLFormatTarget *myFormTarget;
myFormTarget = new StdOutFormatTarget();
theOutput->setByteStream(myFormTarget);
theSerializer->write(node,theOutput);
delete myFormTarget;
theSerializer->release();
theOutput->release();
}
示例12: LocalFileFormatTarget
Triggerconf::~Triggerconf ()
{
if( savechanges ){
//
// save file
//
static const XMLCh gLS [] = {chLatin_L, chLatin_S, chNull};
DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(gLS);
DOMLSSerializer* writer = ((DOMImplementationLS*)impl)->createLSSerializer();
if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTBOM, true))
writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTBOM, true);
XMLFormatTarget* target = new LocalFileFormatTarget (file.c_str ());
target->flush();
DOMLSOutput* output = ((DOMImplementationLS*)impl)->createLSOutput();
output->setByteStream( target );
writer->write( rootnode , output );
writer->release();
delete target;
delete output;
} // if( savechanges )
//
// delete all stuff here
//
delete parser;
delete errhandler;
//
// now we can safely terminate xerces
//
XMLPlatformUtils::Terminate();
}
示例13: commit
int XmlParser::commit(const char* xmlFile) {
try {
// Obtain DOM implementation supporting Load/Save
DOMImplementationLS* pImplementation = dynamic_cast<DOMImplementationLS *>(DOMImplementationRegistry::getDOMImplementation(DualString("LS").asXMLString()));
if (pImplementation == NULL){
throw( std::runtime_error( "Unable to obtain suitable DOMImplementation!" ) ) ;
}
DOMLSSerializer *pSerializer = pImplementation->createLSSerializer();
DOMLSOutput *pOutput = pImplementation->createLSOutput();
#if 1
// Change output format to be pretty (but it isn't)
DOMConfiguration *pConfiguration = pSerializer->getDomConfig();
if (pConfiguration->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
pConfiguration->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
#if 0
// Overrides above but seems to have little effect!
if (pConfiguration->canSetParameter(XMLUni::fgDOMWRTCanonicalForm, true))
pConfiguration->setParameter(XMLUni::fgDOMWRTCanonicalForm, true);
#endif
#if 1
//
if (pConfiguration->canSetParameter(XMLUni::fgDOMWRTEntities, true))
pConfiguration->setParameter(XMLUni::fgDOMWRTEntities, true);
#endif
#endif
LocalFileFormatTarget *pTarget = new LocalFileFormatTarget(DualString( xmlFile ).asXMLString());
pOutput->setByteStream(pTarget);
// mergeDocument->normalizeDocument(); // Needed?
pSerializer->write(mergeDocument, pOutput);
delete pTarget;
pOutput->release();
pSerializer->release();
} catch( const xercesc::XMLException& e ){
return -1;
}
return 0;
}
示例14: PrintXMLdoc
void PrintXMLdoc(const XERCES_CPP_NAMESPACE::DOMDocument* doc)
{
DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(L"Core");
DOMLSSerializer *theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
DOMLSOutput *theOutputDesc = ((DOMImplementationLS*)impl)->createLSOutput();
DOMConfiguration* serializerConfig=theSerializer->getDomConfig();
if (serializerConfig->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
serializerConfig->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
XMLFormatTarget *outputStream = new StdOutFormatTarget();
theOutputDesc->setByteStream(outputStream);
theSerializer->write(doc, theOutputDesc);
theOutputDesc->release();
theSerializer->release();
delete outputStream;
}
示例15: Write
bool XMLIO::Write (DOMImplementation* impl, DOMNode* node, string filename) {
XMLFormatTarget* mft;
if (filename.empty())
mft = new StdOutFormatTarget();
else
mft = new LocalFileFormatTarget (StrX(filename).XMLchar());
// Xerces 2
#ifdef XSEC_XERCES_HAS_SETIDATTRIBUTE
DOMWriter* serializer = ((DOMImplementationLS*)impl)->createDOMWriter();
if (serializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true))
serializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
serializer->writeNode(mft, *node);
serializer->release();
#endif
#ifdef XSEC_XERCES_HAS_BOOLSETIDATTRIBUTE
DOMLSSerializer* serializer = ((DOMImplementationLS*) impl)->createLSSerializer();
DOMLSOutput* output = ((DOMImplementationLS*)impl)->createLSOutput();
DOMConfiguration* configuration = serializer->getDomConfig();
if (configuration->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
configuration->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
output->setByteStream (mft);
serializer->write(node, output);
output->release();
serializer->release();
#endif
return true;
}