#!/bin/ch /* Copyright (c) Oracle Corporation 1999. All Rights Reserved. */ /* NAME DOMSample.c - Sample DOM usage DESCRIPTION Sample usage of C XML parser via DOM interface */ #include "xdkkit.h" #include #ifndef ORATYPES # include #endif #ifndef ORAXML_ORACLE # include #endif #define DOCUMENT (oratext *) "c:/Inetpub/wwwroot/chxml/demos/xdk/cleo.xml" void dump(xmlctx *ctx, xmlnode *node); void dumppart(xmlctx *ctx, xmlnode *node, boolean indent); int main() { Response.setContentType(contenttype); Response.begin(); //Response.title(title); xmlctx *ctx; uword ecode; puts("XML C DOM sample"); puts("Initializing XML package..."); if (!(ctx = xmlinit(&ecode, (const oratext *) 0, (void (*)(void *, const oratext *, uword)) 0, (void *) 0, (const xmlsaxcb *) 0, (void *) 0, (const xmlmemcb *) 0, (void *) 0, (const oratext *) 0))) { printf("Failed to initialze XML parser, error %u\n", (unsigned) ecode); return 1; } printf("Parsing '%s' ...\n", DOCUMENT); if (ecode = xmlparse(ctx, DOCUMENT, (oratext *) 0, XML_FLAG_VALIDATE | XML_FLAG_DISCARD_WHITESPACE)) { printf("Parse failed, error %u\n", (unsigned) ecode); return 1; } puts("Outlining..."); dump(ctx, getDocumentElement(ctx)); xmlterm(ctx); Response.end(); return 0; } void dump(xmlctx *ctx, xmlnode *node) { const oratext *name; void *nodes; uword i, n_nodes; name = getNodeName(node); if (!strcmp((char *) name, "ACT")) dumppart(ctx, node, FALSE); else if (!strcmp((char *) name, "SCENE")) dumppart(ctx, node, TRUE); if (hasChildNodes(node)) { nodes = getChildNodes(node); n_nodes = numChildNodes(nodes); for (i = 0; i < n_nodes; i++) dump(ctx, getChildNode(nodes, i)); } } void dumppart(xmlctx *ctx, xmlnode *node, boolean indent) { void *title = getFirstChild(node); if (indent) fputs(" ", stdout); puts((char *) getNodeValue(getFirstChild(title))); } /* end of DOMSample.c */