Xerces - Serializing DTD Grammar
Hello. I am trying to generate XML logs from scratch using the Xerces-C library. I have found that I can load a dtd definitions file to use for the XercesDOMParser: http://xml.apache.org/xerces-c/apiDo...DOMParser.html using XercesDOMParser::loadGrammar and XercesDOMParser::setLoadExternalDTD but I am trying to write serialize a the log I use a DOMWrite: http://xml.apache.org/xerces-c/apiDo...DOMWriter.html like this
Code:
DOMImplementationLS * impl = (DOMImplementationLS *)
DOMImplementationRegistry::getDOMImplementation(XS("LS"));
DOMWriter * writer = impl->createDOMWriter();
if (writer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true))
writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
if (writer->canSetFeature(XMLUni::fgDOMWRTBOM, true))
writer->setFeature(XMLUni::fgDOMWRTBOM, true);
XMLFormatTarget * ft = new LocalFileFormatTarget(m_file.c_str());
writer->writeNode(ft, *m_doc);
writer->release();
I cannot find any settings that would allow me to add a grammar to the serialization. I have found the class XMLGrammarPool: http://xml.apache.org/xerces-c/apiDo...ammarPool.html that has a method XMLGrammarPool::serializeGrammars, but I cannot figure out how to use it. In Java, I have seen code that uses an 'OutputFileFormat' class that has a OutputFileFormat.setDoctype method, but I cannot find any equivalent to use in the xerces-c API.
Kind of an obscure question, but does anyone have any insight?
Re: Xerces - Serializing DTD Grammar
The serialize grammars thing doesn't make any sense to me. I tried it
Code:
DOMImplementationLS * impl = (DOMImplementationLS *)
DOMImplementationRegistry::getDOMImplementation(XS("[removed]"));
DOMWriter * writer = impl->createDOMWriter();
if (writer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true))
writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
if (writer->canSetFeature(XMLUni::fgDOMWRTBOM, true))
writer->setFeature(XMLUni::fgDOMWRTBOM, true);
std::auto_ptr<MemoryManager> mem_mgr = new MemoryManagerImpl();
std::auto_ptr<XMLGrammarPool> gp = new XMLGrammarPoolImpl(mem_mgr.get());
gp->cacheGrammar(m_grammar);
std::auto_ptr<XMLFormatTarget> ft = new LocalFileFormatTarget(m_file.c_str());
std::auto_ptr<BinOutputStream> bp = new BinFileOutputStream((m_file + "grammar").c_str());
gp->serializeGrammars(bp.get());
writer->writeNode(ft.get(), *m_doc);
writer->release();
And the grammar file looks like this http://zxcvbn.t35.com/test.xmlgrammar
Other ideas appreciated
Re: Xerces - Serializing DTD Grammar
The DOMDocument interface specifies this http://xml.apache.org/xerces-c/apiDo...ent.html#z57_8 'getDoctype' method but goes on to say
>> The DOM Level 2 does not support editing the Document Type Declaration. docType cannot be altered in any way, including through the use of methods inherited from the DOMNode interface, such as insertNode or removeNode.
I'd like to be able to just set the doctype of the xml document I'm synthesizing, I don't need to change it.