Home modules.gotpike.org
Username: Password: [Create Account]
[Forgot Password?]

Modules

ADT
Database
GTK2
GUI
IP
PiJAX
Public
Sql
Stdio
Subversion
System
Tools
Xosd
lua
v4l2
wx

Recent Changes

Public.Parser.XML2 1.50
Public.ZeroMQ 1.1
Public.Template.Mustache 1.0
Public.Protocols.XMPP 1.4
Sql.Provider.jdbc 1.0

Popular Downloads

Public.Parser.JSON2 1.0
Public.Parser.JSON 0.2
GTK2 2.23
Public.Web.FCGI 1.8
Public.Parser.XML2 1.48


Module Information
Public.Parser.XML2
Viewing contents of Public_Parser_XML2-1.50/RelaxNG.cmod

/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * $Id: RelaxNG.cmod,v 1.4 2005-07-20 21:08:14 hww3 Exp $
 */

/*
 * File licensing and authorship information block.
 *
 * Version: MPL 1.1/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Initial Developer of the Original Code is
 *
 * Bill Welliver 
 *
 * Portions created by the Initial Developer are Copyright (C) Bill Welliver
 * All Rights Reserved.
 *
 * Contributor(s):
 *
 * Alternatively, the contents of this file may be used under the terms of
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of the LGPL, and not to allow others to use your version
 * of this file under the terms of the MPL, indicate your decision by
 * deleting the provisions above and replace them with the notice
 * and other provisions required by the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL or the LGPL.
 *
 * Significant Contributors to this file are:
 *
 *
 */

#define THIS_IS_XML2_RELAXNG 1
#include "xml2.h"

/*! @module Public
 */

/*! @module Parser
 */

/*! @module XML2
 */

/*! @class RelaxNG
 *!
 *!  a Relax-NG validator.
 *!
 */
#ifdef HAVE_LIBXML_RELAXNG_H

PIKECLASS RelaxNG

{
  CVAR RELAXNG_OBJECT_DATA * object_data;
  PIKEVAR object node;


/*! @decl int validate_doc(Node node)
 *!
 *! Validates an XML document.
 *!
 *! @returns
 *!   0 if the document is valid, a positive error code number otherwise 
 *!   and -1 in case of internal or API error.
 *!
 */
  PIKEFUN int validate_doc(object node)
  {
    xmlDocPtr doc;
    xmlRelaxNGValidCtxtPtr validator;
    int res;

    CHECK_NODE_PASSED(node);    
    doc = OBJ2_NODE(node)->object_data->node->doc;
    
    if(doc == NULL)
    {
      pop_stack();
      Pike_error("The Node object passed is not part of a larger XML document.\n");
    }


    validator = xmlRelaxNGNewValidCtxt(THIS->object_data->valid);

/*
    xmlRelaxNGSetValidErrors(validator, relaxng_error_handler,
                            relaxng_warning_handler, NULL);
*/

    xmlRelaxNGSetValidErrors(validator, relaxng_error_handler,
                            relaxng_warning_handler, NULL);

    res = xmlRelaxNGValidateDoc(validator, doc);

    pop_stack();

    push_int(res);

    return;

  }

  PIKEFUN void create()
  {

  }

  INIT
  {
   RELAXNG_OBJECT_DATA * relaxng;

   relaxng = malloc(sizeof(RELAXNG_OBJECT_DATA));

   if(relaxng == NULL) 
     Pike_error("relaxng_init: out of memory.\n");

   relaxng->context = NULL;
   relaxng->valid = NULL;

   THIS->object_data = relaxng;
  }
 
  EXIT
  {

  if((* THIS->object_data->refs)==1)
  {
    if(THIS->object_data->context != NULL)
    {
      xmlRelaxNGFreeParserCtxt(THIS->object_data->context);  
    }

    if(THIS->object_data->valid != NULL)
    {
      xmlRelaxNGFree(THIS->object_data->valid);  
    }
 


  }
  else
  {
   (*( THIS->object_data->refs)) --;
  }

  if(THIS->node != NULL)
  {
// FIXME: this is a memory leak!!!
//    free_object(THIS->node);
  } 

  if(THIS->object_data)
    free(THIS->object_data);
  }


}

#endif /* HAVE_LIBXML_RELAXNG_H */

/*! @endclass 
 *!
 */

/*! @endmodule
 *!
 */

/*! @endmodule
 *!
 */

/*! @endmodule
 *!
 */

void pike_init_xml2_relaxng(void)
{
  INIT
}

void pike_exit_xml2_relaxng(void)
{
  EXIT
}

 




gotpike.org | Copyright © 2004 - 2019 | Pike is a trademark of Department of Computer and Information Science, Linköping University