int main(int argc, char **argv) { xmlctx *xctx; xmldocnode *doc; saxctx sc; xmlerr ecode; puts("XML C SAX sample"); memset(&sc, sizeof(sc), 0); sc.keyword = (oratext *) ((argc > 1) ? argv[1] : DEFAULT_KEYWORD); sc.keylen = strlen(sc.keyword); sc.elem = (oratext *) ""; puts("Creating XML context..."); if (!(xctx = XmlCreate(&ecode, (oratext *) "saxsample_xctx", NULL))) { printf("Failed to create XML context, error %u\n", (unsigned) ecode); return 1; } printf("Parsing '%s' and looking for lines containing '%s'...\n", DOCUMENT, sc.keyword); if (argc < 2) puts("[Supply another word as argument to search for something else]"); if (ecode = XmlLoadSax(xctx, &saxcb, &sc, "file", DOCUMENT, "validate", TRUE, "discard_whitespace", TRUE, NULL)) return 1; XmlDestroy(xctx); /* terminate XML package */ return 0; }
Long CBLScriptParser:: Parse( PVoid pScript, SizeT ScriptSize, SBLScriptBase *pScriptInfo, SizeT BufferSize ) { Long Result; SXmlInfo XmlInfo; SXmlNode *pNode; if (pScript == NULL || pScriptInfo == NULL) return BL_ERROR_INVALID_PARAMETER; pScriptInfo->ScriptType = BL_SCRIPT_TYPE_UNKNOWN; if (!XmlParse(pScript, &XmlInfo)) return BL_ERROR_INVALID_FORMAT; pNode = XmlInfo.pNode; if (pNode == NULL) return BL_ERROR_INVALID_FORMAT; if (!StrCompare(pNode->pszNodeName, BL_SCRIPT_CONFIG_ROOT_TAG)) { Result = ParseScriptConfig(&XmlInfo, (SBLScriptConfig *)pScriptInfo, BufferSize); } else if (!StrCompare(pNode->pszNodeName, BL_SCRIPT_LIST_ROOT_TAG)) { Result = ParseScriptGameList(&XmlInfo, (SBLScriptGameList *)pScriptInfo, BufferSize); } else if (!StrCompare(pNode->pszNodeName, BL_SCRIPT_PLUGIN_ROOT_TAG)) { Result = ParseScriptPlugin(&XmlInfo, (SBLScriptPlugin *)pScriptInfo, BufferSize); } else { Result = BL_ERROR_INVALID_FORMAT; } XmlDestroy(&XmlInfo); if (BL_FAILED(Result)) FreeScriptInfo(pScriptInfo); return Result; }
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; }
/* ========================================================================== main ---------------------------------------------------------------------------*/ int main (sword argc, char *argv[]) { xmlctx *xctx; xmlxvmcomp *comp = NULL; xmlxvm *vm = NULL; xmldocnode *xmldom; xvmobj *obj; int i; oratext *xpath; oratext *xmlFile = NULL; oratext *baseuri = NULL; ub2 *code = NULL; xmlerr err = XMLERR_OK; if (argc < 3) { printf("Usage is: XVMXPathSample <xmlfile> <xpath>\n"); return -1; } xmlFile = (oratext*)argv[1]; xpath = (oratext*)argv[2]; /* create xml meta-context */ xctx = XmlCreate(&err, (oratext *) "xvmxpath", "data_encoding", (oratext*)"utf-8", NULL); if (!xctx) { printf("Failed to create xctx: %d\n", err); return -1; } /* create XSL/XPath Compiler */ comp = XmlXvmCreateComp (xctx); if (!comp) { printf("Failed to create Compiler"); goto clean; } /* create XSLT Virtual Machine (XVM) */ vm = XmlXvmCreate (xctx, NULL); if (!vm) { printf("Failed to create VM"); goto clean; } /* Compile the XPath expression */ code = XmlXvmCompileXPath (comp, xpath, NULL, &err); if (!code) { printf("Failed to compile xpath: %d\n", err); return -1; } err = XmlXvmSetBytecodeBuffer (vm, code, XmlXvmGetBytecodeLength(code, &err)); /* Parse the XML file */ xmldom = XmlLoadDom(xctx, &err, "file", xmlFile, NULL); XmlDomSetDocOrder(xctx, (xmlnode *) xmldom, 0); /* evaluate the XPath expression */ obj = (xvmobj*)XmlXvmEvaluateXPath (vm, code, 1, 1, XmlDomGetDocElem(xctx, xmldom)); if (!obj) { printf("Failed to evaluate xpath\n"); return -1; } switch (XmlXvmGetObjectType(obj)) { case XMLXVM_TYPE_BOOL: printf("Boolean Value : %d\n", (int)XmlXvmGetObjectBoolean(obj)); break; case XMLXVM_TYPE_NUM: printf("Numeric Value : %10.2f\n", XmlXvmGetObjectNumber(obj)); break; case XMLXVM_TYPE_FRAG: printf("Obtained result tree fragment\n"); break; case XMLXVM_TYPE_STR: printf("String Value : %s\n", XmlXvmGetObjectString(obj)); break; case XMLXVM_TYPE_NDSET: printf("NodeSet:\n"); for (i = 0; i < XmlXvmGetObjectNSetNum (obj); i++) { xmlnode *node; xmlnodetype type; node = XmlXvmGetObjectNSetNode (obj, i); type = XmlDomGetNodeType(xctx, node); if (type == XMLDOM_ELEM || type == XMLDOM_ATTR) { printf("Node Name : %s\n", XmlDomGetNodeName(xctx, node)); } else { printf("Node Value : %s\n", XmlDomGetNodeValue(xctx, node)); } } break; } clean: /* ========================= Clean =========================== */ if (vm) XmlXvmDestroy(vm); if (comp) XmlXvmDestroyComp(comp); if (xctx) XmlDestroy(xctx); return 0; }
int main(int argc, char **argv) { xmlctx *xctx; xmlerr xerr; xmldocnode *docnode; xsdctx *scctx; char *doc, *schema; xmlnode *root; puts("XML C Schema processor"); if ((argc < 2) || (argc > 3)) { puts("usage: validate <xml document> [schema]"); return -1; } doc = argv[1]; schema = (argc > 2) ? argv[2] : 0; puts("Initializing XML package..."); xctx = XmlCreate(&xerr, (oratext *) "xsdtest", NULL); if (xerr) { printf("Failed to initialze XML meta context, error %u\n", (unsigned) xerr); return 1; } printf("Parsing '%s' ...\n", doc); if (!(docnode = XmlLoadDom(xctx, &xerr, "uri", doc, NULL))) { printf("Parse of %s failed, error %u\n", doc, (unsigned) xerr); return 2; } root = XmlDomGetDocElem(xctx, docnode); puts("Initializing Schema package..."); if (!(scctx = XmlSchemaCreate(xctx, &xerr, NULL))) { printf("Failed, code %u!\n", (unsigned) xerr); return 3; } puts("Validating document..."); if (schema) { xerr = XmlSchemaLoad(scctx, (oratext *)schema, (ub4) 0); if (xerr) { printf("Failed to load %s, error %u\n", schema, (unsigned) xerr); return 4; } } if (xerr = XmlSchemaValidate(scctx, xctx, root)) { printf("Validation failed, error %u\n", (unsigned) xerr); return 5; } puts("Document is valid."); XmlSchemaDestroy(scctx); XmlDestroy(xctx); return 0; }