本文整理汇总了C++中DOMConfiguration::setParameter方法的典型用法代码示例。如果您正苦于以下问题:C++ DOMConfiguration::setParameter方法的具体用法?C++ DOMConfiguration::setParameter怎么用?C++ DOMConfiguration::setParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMConfiguration
的用法示例。
在下文中一共展示了DOMConfiguration::setParameter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: serialize
void musicxml::serialize(std::ostream &os, musicxml::score_timewise const &s) {
xml::auto_initializer xerces_platform { true, false };
DOMImplementation *dom {
DOMImplementationRegistry::getDOMImplementation(ls_id)
};
xml::string score_type("score-timewise");
xml::string dtd_public("-//Recordare//DTD MusicXML " + s.version() +
" Timewise//EN");
xml::string dtd_system("http://www.musicxml.org/dtds/timewise.dtd");
std::unique_ptr<DOMDocument> doc {
dom->createDocument (
nullptr, score_type.c_str(),
dom->createDocumentType(score_type.c_str(), dtd_public.c_str(),
dtd_system.c_str())
)
};
musicxml::score_timewise_(*doc, s);
xsd::cxx::tree::error_handler<char> eh;
xml::dom::bits::error_handler_proxy<char> ehp { eh };
xml::dom::ostream_format_target oft { os };
std::unique_ptr<DOMLSSerializer> writer { dom->createLSSerializer() };
DOMConfiguration *conf { writer->getDomConfig() };
conf->setParameter(XMLUni::fgDOMErrorHandler, &ehp);
conf->setParameter(XMLUni::fgDOMWRTDiscardDefaultContent, true);
conf->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
std::unique_ptr<DOMLSOutput> output { dom->createLSOutput() };
output->setEncoding(xml::string("UTF-8").c_str());
output->setByteStream(&oft);
writer->write(doc.get(), output.get());
eh.throw_if_failed<xsd::cxx::tree::serialization<char>>();
}
示例2: 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;
}
示例3: convertDomToString
string XmlUtil::convertDomToString() {
if(!doc)
throw "DOM is empty"; // FIXME add an exception type for this
DOMImplementationLS* implLS = dynamic_cast<DOMImplementationLS*>(impl);
DOMLSSerializer* theSerializer = implLS->createLSSerializer();
DOMConfiguration* serializerConfig = theSerializer->getDomConfig();
if (serializerConfig->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
serializerConfig->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
string stringTemp = XMLString::transcode (theSerializer->writeToString(doc));
theSerializer->release();
/*string stringDump;
for (string::iterator it = stringTemp.begin() ; it < stringTemp.end(); ++it) {
if (!isspace (*it))
stringDump += *it;
}
return stringDump;*/
return stringTemp;
}
示例4: 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;
}
示例5: ObtainParser
DOMLSParser* ObtainParser(DOMErrorHandler& errHandler) {
const XMLCh ls_id [] = {chLatin_L, chLatin_S, chNull};
// Get an implementation of the Load-Store (LS) interface.
//
DOMImplementation* impl(DOMImplementationRegistry::getDOMImplementation (ls_id));
DOMLSParser *parser (impl->createLSParser (DOMImplementationLS::MODE_SYNCHRONOUS, 0));
DOMConfiguration* conf (parser->getDomConfig ());
// Discard comment nodes in the document.
//
conf->setParameter (XMLUni::fgDOMComments, false);
// Enable datatype normalization.
//
conf->setParameter (XMLUni::fgDOMDatatypeNormalization, true);
// Do not create EntityReference nodes in the DOM tree. No
// EntityReference nodes will be created, only the nodes
// corresponding to their fully expanded substitution text
// will be created.
//
conf->setParameter (XMLUni::fgDOMEntities, false);
// Perform namespace processing.
//
conf->setParameter (XMLUni::fgDOMNamespaces, true);
// Do not include ignorable whitespace in the DOM tree.
//
conf->setParameter (XMLUni::fgDOMElementContentWhitespace, false);
// Enable/Disable validation.
//
conf->setParameter (XMLUni::fgDOMValidate, false);
conf->setParameter (XMLUni::fgXercesSchema, false);
conf->setParameter (XMLUni::fgXercesSchemaFullChecking, false);
// Xerces-C++ 3.1.0 is the first version with working multi import
// support.
//
#if _XERCES_VERSION >= 30100
conf->setParameter (XMLUni::fgXercesHandleMultipleImports, true);
#endif
// We will release the DOM document ourselves.
//
conf->setParameter (XMLUni::fgXercesUserAdoptsDOMDocument, true);
// Set error handler.
//
conf->setParameter (XMLUni::fgDOMErrorHandler, &errHandler);
return parser;
}
示例6: sl
SecureDOMParser::SecureDOMParser(const string &schema_location)
{
DOMConfiguration *conf = getDomConfig();
// Discard comment nodes in the document.
conf->setParameter(XMLUni::fgDOMComments, false);
// Enable datatype normalization.
conf->setParameter(XMLUni::fgDOMDatatypeNormalization, true);
// Do not create EntityReference nodes in the DOM tree. No
// EntityReference nodes will be created, only the nodes
// corresponding to their fully expanded substitution text
// will be created.
conf->setParameter(XMLUni::fgDOMEntities, false);
conf->setParameter(XMLUni::fgDOMNamespaces, true);
conf->setParameter(XMLUni::fgDOMElementContentWhitespace, false);
// Enable validation.
conf->setParameter(XMLUni::fgDOMValidate, !schema_location.empty());
conf->setParameter(XMLUni::fgXercesSchema, !schema_location.empty());
conf->setParameter(XMLUni::fgXercesSchemaFullChecking, false);
if(!schema_location.empty())
{
xml::string sl(schema_location);
conf->setParameter(XMLUni::fgXercesSchemaExternalSchemaLocation, sl.c_str());
}
// Xerces-C++ 3.1.0 is the first version with working multi import
// support.
conf->setParameter(XMLUni::fgXercesHandleMultipleImports, true);
// We will release the DOM document ourselves.
conf->setParameter(XMLUni::fgXercesUserAdoptsDOMDocument, true);
}
示例7: evaluate
//.........这里部分代码省略.........
// Replace the document element
DOMElement * elt = doc->getDocumentElement();
doc->replaceChild(xenc->getElement(), elt);
elt->release();
}
else {
// Document encryption
cipher->encryptElement(doc->getDocumentElement(), keyAlg);
}
// Do we encrypt a created key?
if (kek != NULL && xenc != NULL) {
XENCEncryptedKey *xkey = cipher->encryptKey(keyStr, keyLen, kekAlg);
// Add to the EncryptedData
xenc->appendEncryptedKey(xkey);
}
}
if (doXMLOutput) {
// Output the result
XMLCh core[] = {
XERCES_CPP_NAMESPACE_QUALIFIER chLatin_C,
XERCES_CPP_NAMESPACE_QUALIFIER chLatin_o,
XERCES_CPP_NAMESPACE_QUALIFIER chLatin_r,
XERCES_CPP_NAMESPACE_QUALIFIER chLatin_e,
XERCES_CPP_NAMESPACE_QUALIFIER chNull
};
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(core);
#if defined (XSEC_XERCES_DOMLSSERIALIZER)
// DOM L3 version as per Xerces 3.0 API
DOMLSSerializer *theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
Janitor<DOMLSSerializer> j_theSerializer(theSerializer);
// Get the config so we can set up pretty printing
DOMConfiguration *dc = theSerializer->getDomConfig();
dc->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, false);
// Now create an output object to format to UTF-8
DOMLSOutput *theOutput = ((DOMImplementationLS*)impl)->createLSOutput();
Janitor<DOMLSOutput> j_theOutput(theOutput);
theOutput->setEncoding(MAKE_UNICODE_STRING("UTF-8"));
theOutput->setByteStream(formatTarget);
theSerializer->write(doc, theOutput);
#else
DOMWriter *theSerializer = ((DOMImplementationLS*)impl)->createDOMWriter();
Janitor<DOMWriter> j_theSerializer(theSerializer);
theSerializer->setEncoding(MAKE_UNICODE_STRING("UTF-8"));
if (theSerializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, false))
theSerializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, false);
theSerializer->writeNode(formatTarget, *doc);
#endif
cout << endl;
}
}
catch (XSECException &e) {
char * msg = XMLString::transcode(e.getMsg());
cerr << "An error occured during encryption/decryption operation\n Message: "
<< msg << endl;
XSEC_RELEASE_XMLCH(msg);
errorsOccured = true;
if (formatTarget != NULL)
delete formatTarget;
doc->release();
return 2;
}
catch (XSECCryptoException &e) {
cerr << "An error occured during encryption/decryption operation\n Message: "
<< e.getMsg() << endl;
errorsOccured = true;
if (formatTarget != NULL)
delete formatTarget;
doc->release();
#if defined (XSEC_HAVE_OPENSSL)
ERR_load_crypto_strings();
BIO * bio_err;
if ((bio_err=BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
ERR_print_errors(bio_err);
#endif
return 2;
}
if (formatTarget != NULL)
delete formatTarget;
doc->release();
return 0;
}
示例8: main
//.........这里部分代码省略.........
}
// Initialize the XML4C system
try
{
if (strlen(localeStr))
{
XMLPlatformUtils::Initialize(localeStr);
}
else
{
XMLPlatformUtils::Initialize();
}
if (recognizeNEL)
{
XMLPlatformUtils::recognizeNEL(recognizeNEL);
}
}
catch (const XMLException& toCatch)
{
XERCES_STD_QUALIFIER cerr << "Error during initialization! :\n"
<< StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
return 1;
}
// Instantiate the DOM parser.
static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(gLS);
DOMLSParser *parser = ((DOMImplementationLS*)impl)->createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS, 0);
DOMConfiguration *config = parser->getDomConfig();
config->setParameter(XMLUni::fgDOMNamespaces, doNamespaces);
config->setParameter(XMLUni::fgXercesSchema, doSchema);
config->setParameter(XMLUni::fgXercesHandleMultipleImports, true);
config->setParameter(XMLUni::fgXercesSchemaFullChecking, schemaFullChecking);
config->setParameter(XMLUni::fgDOMDisallowDoctype, disallowDoctype);
if (valScheme == AbstractDOMParser::Val_Auto)
{
config->setParameter(XMLUni::fgDOMValidateIfSchema, true);
}
else if (valScheme == AbstractDOMParser::Val_Never)
{
config->setParameter(XMLUni::fgDOMValidate, false);
}
else if (valScheme == AbstractDOMParser::Val_Always)
{
config->setParameter(XMLUni::fgDOMValidate, true);
}
// enable datatype normalization - default is off
config->setParameter(XMLUni::fgDOMDatatypeNormalization, true);
// And create our error handler and install it
DOMCountErrorHandler errorHandler;
config->setParameter(XMLUni::fgDOMErrorHandler, &errorHandler);
//
// Get the starting time and kick off the parse of the indicated
// file. Catch any exceptions that might propogate out of it.
//
unsigned long duration;
bool more = true;
示例9: main
//.........这里部分代码省略.........
docFirstElementChildChild->setAttributeNS(XMLUni::fgXMLNSURIName, X("xmlns:NS1"), X("http://testclash.com"));
//clash with standard prefix
docFirstElementChildChild->setAttributeNS(X("http://testattr5.com"), X("po:attr10"), X("value"));
doc->normalizeDocument();
normalizer->serializeNode(doc);
XERCES_STD_QUALIFIER cout << "\n\n";
//2 prefix with the same uri
docFirstElementChildChild = doc->createElementNS(X("http://www.uri1.com"),X("docEleChildChild6"));
docFirstElementChild->appendChild(docFirstElementChildChild);
docFirstElementChildChild->setAttributeNS(XMLUni::fgXMLNSURIName, X("xmlns:uri1"), X("http://www.uri1.com"));
docFirstElementChildChild->setAttributeNS(XMLUni::fgXMLNSURIName, X("xmlns:uri1b"), X("http://www.uri1.com"));
docFirstElementChildChild->setAttributeNS(X("http://www.uri1.com"), X("uri1:attr1"), X("value"));
docFirstElementChildChild->setAttributeNS(X("http://www.uri1.com"), X("uri1b:attr2"), X("value"));
doc->normalizeDocument();
normalizer->serializeNode(doc);
XERCES_STD_QUALIFIER cout << "\n\n";
//check to see we use the nearest binding and for more inheritence
DOMElement *docFirstElementChildChildChild = doc->createElementNS(X("http://www.uri1.com"),X("docEleChildChildChild"));
docFirstElementChildChild->appendChild(docFirstElementChildChildChild);
docFirstElementChildChild->setAttributeNS(XMLUni::fgXMLNSURIName, X("xmlns:nearerThanPo"), X("http://www.test.com"));
docFirstElementChildChildChild->setAttributeNS(X("http://testattr.com"), X("attr2"), X("value"));
docFirstElementChildChildChild->setAttributeNS(X("http://www.test.com"), X("attr1"), X("value"));
doc->normalizeDocument();
normalizer->serializeNode(doc);
XERCES_STD_QUALIFIER cout << "\n\n";
//NS1.1 stuff
//test creating default prefix when NS1 has been set to ""
noNamespaceEle->setAttributeNS(XMLUni::fgXMLNSURIName, X("xmlns:NS1"), X(""));
DOMElement *noNamespaceChild = doc->createElementNS(X("http://testclash.com"),X("testing1.1Stuff"));
noNamespaceEle->appendChild(noNamespaceChild);
doc->normalizeDocument();
normalizer->serializeNode(doc);
noNamespaceChild = doc->createElementNS(X("http://testclash.com"),X("NS1:testing1.1Stuff"));
noNamespaceEle->appendChild(noNamespaceChild);
noNamespaceChild->setAttributeNS(X("http://www.someRandomUri.com"), X("attr"), X("value"));
doc->normalizeDocument();
normalizer->serializeNode(doc);
//check error conditions
XERCES_STD_QUALIFIER cout << "error conditions" << XERCES_STD_QUALIFIER endl;
DOMConfiguration *conf = doc->getDOMConfig();
conf->setParameter(XMLUni::fgDOMErrorHandler, normalizer);
conf->setParameter(XMLUni::fgDOMNamespaces, true);
DOMElement *level1Node = doc->createElement(X("level1Node"));
docFirstElement->appendChild(level1Node);
doc->normalizeDocument();
docFirstElement->removeChild(level1Node);
docFirstElement->setAttribute(X("level1Attr"), X("level1"));
doc->normalizeDocument();
docFirstElement->removeAttribute(X("level1Attr"));
//cant check this as Xerces does not let us do it
// noNamespaceChild->setAttributeNS(X("http://www.someRandomUri.com"), X("xmlns"), X("value"));
// doc->normalizeDocument();
//lets do a sanity test on a comment
DOMComment *comment = doc->createComment(X("some comment"));
docFirstElement->appendChild(comment);
doc->normalizeDocument();
normalizer->serializeNode(doc);
conf->setParameter(XMLUni::fgDOMComments, false);
docFirstElement->appendChild(comment);
doc->normalizeDocument();
normalizer->serializeNode(doc);
//and on a CDATA
DOMCDATASection *cData = doc->createCDATASection(X("some cdata"));
docFirstElement->appendChild(cData);
doc->normalizeDocument();
normalizer->serializeNode(doc);
conf->setParameter(XMLUni::fgDOMCDATASections, false);
docFirstElement->appendChild(cData);
doc->normalizeDocument();
normalizer->serializeNode(doc);
delete normalizer;
delete tmpTrue;
delete tmpFalse;
return 0;
}
示例10: memset
DOMDocument *CouchRunHttpServer::parsePrologue( std::string S_PrologueXMLFilename ){
bool recognizeNEL = false;
char localeStr[64];
memset(localeStr, 0, sizeof localeStr);
// Initialize the XML4C system
try {
if (strlen(localeStr)) {
XMLPlatformUtils::Initialize(localeStr);
}
else{
XMLPlatformUtils::Initialize();
}
if (recognizeNEL){
XMLPlatformUtils::recognizeNEL(recognizeNEL);
}
}
catch (const XMLException& toCatch){
XERCES_STD_QUALIFIER cerr << "Error during initialization! :\n"
<< StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
return NULL;
}
// Instantiate the DOM parser.
static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };
DOMImplementation *impl =
DOMImplementationRegistry::getDOMImplementation(gLS);
DOMLSParser *parser =
((DOMImplementationLS*)impl)->createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS, 0);
DOMConfiguration *config = parser->getDomConfig();
// enable datatype normalization - default is off
config->setParameter(XMLUni::fgDOMDatatypeNormalization, true);
// And create our error handler and install it
DOMCountErrorHandler errorHandler;
config->setParameter(XMLUni::fgDOMErrorHandler, &errorHandler);
//
// Get the starting time and kick off the parse of the indicated
// file. Catch any exceptions that might propogate out of it.
//
unsigned long duration;
const char *xmlFile = 0;
bool more = true;
XERCES_STD_QUALIFIER ifstream fin;
// Later possibly a list of prologue files rather than a single one
while (more){
xmlFile = S_PrologueXMLFilename.c_str();
more = false;
}
// Parse XML prologue file
// Reset error count first
errorHandler.resetErrors();
bool errorOccurred = false;
try{
// reset document pool
parser->resetDocumentPool();
const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *doc = parser->parseURI(xmlFile);
const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
duration = endMillis - startMillis;
// Print out the stats that we collected and time taken.
XERCES_STD_QUALIFIER cout << "Parsed "
<< xmlFile << ": " << duration << " ms."
<< XERCES_STD_QUALIFIER endl;
return doc;
}
catch (const XMLException& toCatch){
XERCES_STD_QUALIFIER cerr << "\nError during parsing: '" << xmlFile << "'\n"
<< "Exception message is: \n"
<< StrX(toCatch.getMessage()) << "\n"
<< XERCES_STD_QUALIFIER endl;
errorOccurred = true;
// continue;
}
catch (const DOMException& toCatch){
const unsigned int maxChars = 2047;
XMLCh errText[maxChars + 1];
XERCES_STD_QUALIFIER cerr << "\nDOM Error during parsing: '"
<< xmlFile << "'\n"
<< "DOMException code is: "
<< toCatch.code
<< XERCES_STD_QUALIFIER endl;
if (DOMImplementation::loadDOMExceptionMsg(toCatch.code, errText, maxChars))
XERCES_STD_QUALIFIER cerr << "Message is: "
<< StrX(errText)
<< XERCES_STD_QUALIFIER endl;
errorOccurred = true;
// continue;
}
catch (...){
//.........这里部分代码省略.........
示例11: gis
static std::unique_ptr<DOMDocument>
dom_document(std::istream &is, const std::string &id, bool validate) {
MemoryManager *mm(XMLPlatformUtils::fgMemoryManager);
std::unique_ptr<XMLGrammarPool> gp(new XMLGrammarPoolImpl(mm));
grammar_input_stream gis(musicxml_schema, sizeof(musicxml_schema));
gp->deserializeGrammars(&gis);
gp->lockPool();
DOMImplementation *dom {
DOMImplementationRegistry::getDOMImplementation(ls_id)
};
std::unique_ptr<DOMLSParser> parser {
dom->createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS, nullptr, mm, gp.get())
};
DOMConfiguration *conf { parser->getDomConfig() };
embedded_resource_resolver resolver;
conf->setParameter(XMLUni::fgDOMResourceResolver, &resolver);
// Discard comment nodes in the document.
conf->setParameter(XMLUni::fgDOMComments, false);
// Enable datatype normalization.
conf->setParameter(XMLUni::fgDOMDatatypeNormalization, true);
// Do not create EntityReference nodes in the DOM tree. No
// EntityReference nodes will be created, only the nodes
// corresponding to their fully expanded substitution text
// will be created.
conf->setParameter(XMLUni::fgDOMEntities, false);
// Perform namespace processing.
conf->setParameter(XMLUni::fgDOMNamespaces, true);
// Do not include ignorable whitespace in the DOM tree.
conf->setParameter(XMLUni::fgDOMElementContentWhitespace, false);
// Enable/Disable validation.
conf->setParameter(XMLUni::fgDOMValidate, validate);
conf->setParameter(XMLUni::fgXercesSchema, validate);
conf->setParameter(XMLUni::fgXercesSchemaFullChecking, false);
// Use the loaded grammar during parsing and disable loading schemas via other
// means (e.g., schemaLocation).
conf->setParameter(XMLUni::fgXercesUseCachedGrammarInParse, true);
conf->setParameter(XMLUni::fgXercesLoadSchema, false);
// Xerces-C++ 3.1.0 is the first version with working multi import
// support.
#if _XERCES_VERSION >= 30100
conf->setParameter(XMLUni::fgXercesHandleMultipleImports, true);
#endif
// We will release the DOM document ourselves.
conf->setParameter(XMLUni::fgXercesUserAdoptsDOMDocument, true);
// Set error handler.
tree::error_handler<char> eh;
xml::dom::bits::error_handler_proxy<char> ehp { eh };
conf->setParameter(XMLUni::fgDOMErrorHandler, &ehp);
// Prepare input stream.
xml::sax::std_input_source isrc { is, id };
Wrapper4InputSource wrap { &isrc, false };
std::unique_ptr<DOMDocument> doc { parser->parse(&wrap) };
eh.throw_if_failed<tree::parsing<char>>();
return doc;
}
示例12: 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
}
示例13: main
// ---------------------------------------------------------------------------
//
// main
//
// ---------------------------------------------------------------------------
int main(int argC, char* argV[])
{
char *testFileName;
char *outputFileName;
for (int argInd = 1; argInd < argC; argInd++)
{
if (!strcmp(argV[argInd], "-?") || !strcmp(argV[argInd], "-h"))
{
/* print help and exit */
usage();
return 2;
}
}
if (argC < 3){
usage();
return 2;
}
testFileName = argV[argC-2];
outputFileName = argV[argC-1];
// Initialize the XML4C system
try
{
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch)
{
XERCES_STD_QUALIFIER cerr << "Error during initialization! :\n"
<< StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
return 1;
}
//============================================================================
// Instantiate the DOM parser to use for the source documents
//============================================================================
static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(gLS);
DOMLSParser *parser = ((DOMImplementationLS*)impl)->createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS, 0);
DOMConfiguration *config = parser->getDomConfig();
config->setParameter(XMLUni::fgDOMNamespaces, true);
config->setParameter(XMLUni::fgXercesSchema, true);
config->setParameter(XMLUni::fgXercesSchemaFullChecking, true);
if(config->canSetParameter(XMLUni::fgXercesDoXInclude, true)){
config->setParameter(XMLUni::fgXercesDoXInclude, true);
}
// enable datatype normalization - default is off
//config->setParameter(XMLUni::fgDOMDatatypeNormalization, true);
// And create our error handler and install it
XIncludeErrorHandler errorHandler;
config->setParameter(XMLUni::fgDOMErrorHandler, &errorHandler);
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *doc = 0;
try
{
// load up the test source document
XERCES_STD_QUALIFIER cerr << "Parse " << testFileName << " in progress ...";
parser->resetDocumentPool();
doc = parser->parseURI(testFileName);
XERCES_STD_QUALIFIER cerr << " finished." << XERCES_STD_QUALIFIER endl;
}
catch (const XMLException& toCatch)
{
XERCES_STD_QUALIFIER cerr << "\nError during parsing: '" << testFileName << "'\n"
<< "Exception message is: \n"
<< StrX(toCatch.getMessage()) << "\n" << XERCES_STD_QUALIFIER endl;
}
catch (const DOMException& toCatch)
{
const unsigned int maxChars = 2047;
XMLCh errText[maxChars + 1];
XERCES_STD_QUALIFIER cerr << "\nDOM Error during parsing: '" << testFileName << "'\n"
<< "DOMException code is: " << toCatch.code << XERCES_STD_QUALIFIER endl;
if (DOMImplementation::loadDOMExceptionMsg(toCatch.code, errText, maxChars))
XERCES_STD_QUALIFIER cerr << "Message is: " << StrX(errText) << XERCES_STD_QUALIFIER endl;
}
catch (...)
{
XERCES_STD_QUALIFIER cerr << "\nUnexpected exception during parsing: '" << testFileName << "'\n";
}
if (!errorHandler.getSawErrors() && doc) {
DOMLSSerializer *writer = ((DOMImplementationLS*)impl)->createLSSerializer();
DOMLSOutput *theOutputDesc = ((DOMImplementationLS*)impl)->createLSOutput();
//.........这里部分代码省略.........
示例14: convertStringToDom
void XmlUtil::convertStringToDom(const string& stringName, const string& schemaFile, const bool validate) {
((DOMImplementationLS*)impl)->createLSSerializer();
parser = ((DOMImplementationLS*)impl)->createLSParser (DOMImplementationLS::MODE_SYNCHRONOUS, 0);
// remove the old DOM
if (doc) {
doc->release();
doc = NULL;
}
if (parser) {
DOMConfiguration* conf (parser->getDomConfig ());
conf->setParameter (XMLUni::fgDOMComments, false);
conf->setParameter (XMLUni::fgDOMDatatypeNormalization, true);
conf->setParameter (XMLUni::fgDOMEntities, false);
conf->setParameter (XMLUni::fgDOMNamespaces, true);
conf->setParameter (XMLUni::fgDOMElementContentWhitespace, false);
// Enable validation.
conf->setParameter (XMLUni::fgDOMValidate, validate);
conf->setParameter (XMLUni::fgXercesSchema, validate);
conf->setParameter (XMLUni::fgXercesSchemaFullChecking, false);
// Use the loaded grammar during parsing.
conf->setParameter (XMLUni::fgXercesUseCachedGrammarInParse, true);
// Don't load schemas from any other source
conf->setParameter (XMLUni::fgXercesLoadSchema, false);
// We will release the DOM document ourselves.
conf->setParameter (XMLUni::fgXercesUserAdoptsDOMDocument, true);
error_handler eh;
parser->getDomConfig ()->setParameter (XMLUni::fgDOMErrorHandler, &eh);
if (validate) {
if (!parser->loadGrammar (schemaFile.c_str(), Grammar::SchemaGrammarType, true)) {
LOG(log::ERROR) << "ERROR: Unable to load schema.xsd";
return;
}
if (eh.failed ()) {
return;
}
}
if (doc) doc->release();
XMLCh* sName = XMLString::transcode(stringName.c_str());
DOMLSInput* input = ((DOMImplementationLS*)impl)->createLSInput();
input->setStringData(sName);
doc = parser->parse(input);
if (eh.failed ()) {
if (doc) doc->release();
doc = NULL;
LOG(log::ERROR) << "problem during parsing of XML file" << endl;
return;
}
XMLString::release(&sName);
}
}
示例15: parse
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* XmlReaderSAR::parse(string fn, string endTag)
{
if (mpDoc != NULL)
{
mpDoc->release();
mpDoc = NULL;
}
DOMConfiguration* pConfig = mpParser->getDomConfig();
const void* pOldError = pConfig->getParameter(XMLUni::fgDOMErrorHandler);
try
{
string uri = XmlBase::PathToURL(fn);
if (!mXmlSchemaLocation.empty())
{
string esl("https://comet.balldayton.com/standards/namespaces/2005/v1/comet.xsd ");
for (unsigned int version = XmlBase::VERSION; version > 0; version--)
{
stringstream fname;
fname << mXmlSchemaLocation << "opticks-" << version << ".xsd";
FILE* pTmp = fopen(fname.str().c_str(), "r");
if (pTmp != NULL)
{
esl += XmlBase::PathToURL(fname.str()) + " ";
fclose(pTmp);
break;
}
}
pConfig->setParameter(XMLUni::fgXercesSchemaExternalSchemaLocation, const_cast<XMLCh*>(X(esl.c_str())));
pConfig->setParameter(XMLUni::fgXercesSchema, true);
pConfig->setParameter(XMLUni::fgXercesSchemaFullChecking, true);
pConfig->setParameter(XMLUni::fgXercesValidationErrorAsFatal, true);
}
if (!endTag.empty())
{
logSimpleMessage("Partial parse is not available...performing complete parse.");
}
XmlReaderErrorHandler errors(this);
pConfig->setParameter(XMLUni::fgDOMErrorHandler, &errors);
mpDoc = mpParser->parseURI(uri.c_str());
}
catch (const XMLException& exc)
{
logException(&exc);
}
catch (const DOMException& exc)
{
logException(dynamic_cast<const XMLException*>(&exc));
}
catch (const XmlBase::XmlException& exc)
{
logSimpleMessage(exc.str());
}
catch (...)
{
logSimpleMessage("XmlReader unexpected parse error");
}
pConfig->setParameter(XMLUni::fgDOMErrorHandler, pOldError);
return mpDoc;
}