Exemplo n.º 1
0
tstring SqlXML::str() const
{
	OCIDuration dur;
	xmlerr xerr = (xmlerr)0;
	oraerr oerr = (oraerr)0;
	struct xmlctx *xctx = (xmlctx*) 0;
//	xmldocnode *doc = (xmldocnode*) 0;
	ocixmldbparam params[1];

	/* Get an XML context */
	params[0].name_ocixmldbparam = XCTXINIT_OCIDUR;
	params[0].value_ocixmldbparam = &dur;

	// TODO add some error checking here
	// TODO this xml context should be "more global"
	xctx = OCIXmlDbInitXmlCtx(_conn._env, _conn._svc_ctx, _conn._env._errh, params, 1);

	orastream *os = OraStreamInit((void*)0xDEAD, (void*)this, &oerr, "write", stream_write_callback, "open", stream_open_callback, NULL);

	boolean op = OraStreamReadable(os);
	oerr = OraStreamOpen(os, NULL);
	printf("Stream os readable %d\n", op);
	op = OraStreamWriteable(os);
	printf("Stream os writeable %d\n", op);

	XmlSaveDom(xctx, &xerr, (xmlnode*)xml, "stream", os, NULL);

	OCIXmlDbFreeXmlCtx(xctx);

	return _stringrepres.str();
};
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
    xmlctx      *xctx = NULL;
    xslctx      *sctx = NULL;
    xmldocnode  *inst_doc = NULL, *ss_doc = NULL;
    xmlfragnode *output_frag;
    xmlerr       ecode;

    puts("XSL Example.");

    /* Check for correct usage */
    if (argc < 3)
    {
	puts("Usage is XSLSample <xmlfile> <xslfile>\n");
	return 1;
    }

    /* create the XML context */
    if (!(xctx = XmlCreate(&ecode, (oratext *) "xslsample_xctx", NULL)))
    {
        printf("Failed to create XML context, error %u\n", (unsigned) ecode);
        goto clean;
    }
 
    printf("Parsing stylesheet '%s'...\n", argv[2]);
    if (!(ss_doc = XmlLoadDom(xctx, &ecode, "file", argv[2], "validate", TRUE,
			      "discard_whitespace", TRUE, NULL)))
    {
        printf("Parse failed, error %u\n", (unsigned) ecode);
        goto clean;
    }

    puts("Creating Stylesheet context...");
    sctx = XmlXslCreate(xctx, ss_doc, (oratext *) argv[2], &ecode);

    printf("Parsing instance document '%s' ...\n", argv[1]);
    if (!(inst_doc = XmlLoadDom(xctx, &ecode, "file", argv[1], "validate", TRUE,
				"discard_whitespace", TRUE, NULL)))
    {
        printf("Parse failed, error %u\n", (unsigned) ecode);
        goto clean;
    }

    /* XSL processing; note that since XmlXslSetOutputStream has not been
       called, the result is a DOM fragment node and not an output stream so
       xsl:output is not supported. */
    puts("XSL Processing...");
    if (ecode = XmlXslProcess(sctx, inst_doc, FALSE))
    {
        printf("Processing failed, error %u\n", (unsigned) ecode);
        goto clean;
    }

    /* Get and print the result */
    output_frag = XmlXslGetOutput(sctx);
    puts("Result:");
    XmlSaveDom(xctx, &ecode, output_frag, "stdio", stdout,
	       "indent_step", 2, NULL);

    /* clean up */
clean:
    if (inst_doc)
        XmlFreeDocument(xctx, inst_doc);
    if (ss_doc)
        XmlFreeDocument(xctx, ss_doc);
    if (sctx)
        XmlXslDestroy(sctx);
    if (xctx)
        XmlDestroy(xctx);

    return 0;
}