--- parser3/src/classes/Attic/dom.C 2001/09/07 12:46:19 1.2 +++ parser3/src/classes/Attic/dom.C 2001/09/10 08:23:49 1.4 @@ -5,7 +5,7 @@ Author: Alexander Petrosyan (http://design.ru/paf) */ -static const char *RCSId="$Id: dom.C,v 1.2 2001/09/07 12:46:19 parser Exp $"; +static const char *RCSId="$Id: dom.C,v 1.4 2001/09/10 08:23:49 parser Exp $"; #if _MSC_VER # pragma warning(disable:4291) // disable warning @@ -19,10 +19,16 @@ static const char *RCSId="$Id: dom.C,v 1 #include #include #include +#include +//#include +#include +#include +#include +#include // defines -#define Dom_CLASS_NAME "dom" +#define DOM_CLASS_NAME "dom" // class @@ -64,14 +70,71 @@ static void _load(Request& r, const Stri vDOM.setParsedSource(parsedSource); } +static void _save(Request& r, const String& method_name, MethodParams *params) { + Pool& pool=r.pool(); + VDOM& vDOM=*static_cast(r.self); + + // filename + const String& filename=params->as_string(0, "file name must not be code"); + + // filespec + const char *filespec=r.absolute(filename).cstr(String::UL_FILE_NAME); + + XalanParsedSource* parsedSource=vDOM.getParsedSource(); + if(!parsedSource) + PTHROW(0, 0, + &method_name, + "on empty document"); + + XalanDocument *document=parsedSource->getDocument(); + +/* + XalanDOMString data; + DOMServices::getNodeData(*document, data); + const XalanDOMChar *cstr=data.c_str(); +^^^^^^^^^^^just a text from one node +*/ + + //const XalanDOMString & theFileName + XalanFileOutputStream fileOutputStream(XalanDOMString(filespec, strlen(filespec))); + XalanOutputStreamPrintWriter outputStreamPrintWriter(fileOutputStream); + FormatterToXML formatterListener(outputStreamPrintWriter); +/* + // Sends the data for a node to a FormatterListener + DOMServices::getNodeData(*document, formatterListener, + (DOMServices::MemberFunctionPtr)formatterListener.characters); + formatterListener.endDocument(); +*/ + // Create a FormatterTreeWalker with the the + // new formatter... + FormatterTreeWalker theTreeWalker(formatterListener); + + // Walk the document and produce the XML... + theTreeWalker.traverse(document); +/* + // Set up a XercesParserLiaison and use it to wrap the DOM_Document + // in a XalanDocument. + XercesDOMSupport theDOMSupport; + XercesParserLiaison theParserLiaison(theDOMSupport); + + // You can also convert the XalanDocument to a Xerces DOM_Document. + DOM_Document xercesDocument = theParserLiaison.mapXercesDocument(xalanDocument); + //DOMPrint sample +*/ + // TODO error handling ... +} + // constructor MDom::MDom(Pool& apool) : Methoded(apool) { - set_name(*NEW String(pool(), Dom_CLASS_NAME)); + set_name(*NEW String(pool(), DOM_CLASS_NAME)); - // ^dom::load[] + // ^dom::load[some.xml] add_native_method("load", Method::CT_DYNAMIC, _load, 1, 1); + // ^dom.save[some.xml] + add_native_method("save", Method::CT_DYNAMIC, _save, 1, 1); + } // global variable @@ -84,6 +147,8 @@ Methoded *MDom_create(Pool& pool) { // You must initialize Xerces-C++ once per process XMLPlatformUtils::Initialize(); XalanTransformer::initialize(); + // Must be called before any other functions are called. +// DOMServices::initialize (); return Dom_class=new(pool) MDom(pool);