[Experience Summary] implement Schema mode verification and XSLT template Conversion Based on libxml + libxslt on Windows Platform

Source: Internet
Author: User
Tags xslt

Step 1: At this URL: http://xmlsoft.org/sources/win32/

Download these packages:

Iconv-1.9.2.win32.zip

Libxml2-2.7.3.win32.zip

Libxslt-1.1.24.win32.zip

Copy the Lib, DLL, and include files to the appropriate location.

 

Step 2:

Compile the test code:

XML Schema:

<Br/> # include "libxml/tree. H "<br/> # include" libxml/parser. H "<br/> # include" libxml/xmlschemas. H "</P> <p> /****************************** * ******************** <br/> @ describle application XML Schema template file verification case document <br/> @ paramschema_filename mode file <br/> @ paramxmldoc case file in XML format <br/> @ retval> = 0 Verification Successful <br/> <0 Verification Failed <br/> ** **************************************** * *********/<br/> int is_valid (const char * schema_filename, const char * xmldoc) {<br/> xmldocptr Doc; <br/> Doc = xmlreadfile (xmldoc, null, xml_parse_nonet | xml_parse_noent ); <br/> If (null = DOC) {<br/> MessageBox (null, "XML document read error", null, null); <br/> return-1; <br/>}< br/> xmldocptr schema_doc = xmlreadfile (schema_filename, null, xml_parse_nonet | xml_parse_noent); <br/> If (null = schema_doc) {<br/> MessageBox (null, "schema read error", null, null); <br/> return-1; <br/>}< br/> xmlschemaparserctxtptr parser_ctxt = xmlschemanewdocparserctxt (schema_doc); <br/> If (null = parser_ctxt) {<br/> return-1; <br/>}< br/> xmlschemaptr schema = xmlschemaparse (parser_ctxt); <br/> If (schema = NULL) {<br/> return-1; <br/>}< br/> xmlschemavalidctxtptr valid_ctxt = xmlschemanewvalidctxt (schema); <br/> If (null = valid_ctxt) {<br/> return-1; <br/>}< br/> int is_valid = (xmlschemavalidatedoc (valid_ctxt, DOC) = 0); </P> <p> xmlschemafreevalidctxt (valid_ctxt ); <br/> xmlschemafree (schema); <br/> xmlschemafreeparserctxt (parser_ctxt); <br/> xmlfreedoc (schema_doc); </P> <p> return is_valid; <br/>}

 

XSLT:

<Br/> # include "libxslt/XSLT. H "<br/> # include" libxslt/xsltinternals. H "<br/> # include" libxslt/transform. H "<br/> # include" libxslt/ubuntutils. H "<br/> /********************************* * ***************** <br/> @ describle application XSLT template conversion case format <br/> @ paramstylesheet XSLT Template File <br/> @ paramolddoc case file to be converted <br/> @ paramnewdoc converted case file <br/> @ retval> = 0 conversion successful <br/> <0 Conversion failed <br/> ************************************ * **************/<br/> int XSLT (const char * stylesheet, const char * olddoc, const char * newdoc) {<br/> const char * Params [16 + 1]; <br/> int ret; <br/> effectstylesheetptr cur = NULL; <br/> xmldocptr doc, Res; <br/> file * outfp; <br/>/* set the parameter */<br/> Params [0] = NULL; <br/>/* Set libxml */<br/> xmlsubstituteentitiesdefault (1 ); <br/> xmlloadextdtddefaultvalue = 1; <br/> cur = effectparsestylesheetfile (const xmlchar *) stylesheet); <br/> If (null = cur) {<br/> MessageBox (null, "error in parsing XSLT template file", null, null); <br/> return-1; <br/>}< br/> Doc = xmlparsefile (olddoc); <br/> res = effectapplystylesheet (cur, Doc, (const char **) Params ); <br/> If (null = res) {<br/> MessageBox (null, "Application Template error", null, null); <br/> return-1; <br/>}< br/> If (null = res-> Children) {<br/> MessageBox (null, "res-> children is null", null, null); <br/> return-1; <br/>}< br/> ret = ~tsaveresulttofilename (newdoc, res, cur, 0 ); <br/> effectfreestylesheet (cur); <br/> xmlfreedoc (RES); <br/> xmlfreedoc (DOC); <br/> effectcleanupglobals (); <br/> xmlcleanupparser (); <br/> return ret; <br/>}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.