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.14/XMLReader.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: XMLReader.cmod,v 1.4 2005/05/04 02:56:26 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_XMLREADER 1

#include "xml2.h"

/*! @module Public
 */

/*! @module Parser
 */

/*! @module XML2
 */

/*! @class XMLReader
 *!
 *! A simplified parser for XML documents. Similar to the C# XMLReader 
 *! class.
 */
#ifdef HAVE_LIBXML_XMLREADER_H

PIKECLASS XMLReader
program_flags PROGRAM_USES_PARENT;
{

  CVAR XMLREADER_OBJECT_DATA   *object_data;

PIKEFUN string _sprintf(int type, mixed t)
{
  char * desc;

  push_text("XMLReader()");
}

PIKEFUN mapping read()
{
  int res;

  if(THIS->object_data->reader == NULL)
  {
    Pike_error("no xmlReader!\n");
  }
  res = xmlTextReaderRead(THIS->object_data->reader);
  if(res == 1) /* we got data to process! */
  {
    push_int(1);
    return;
  }
  else if (res == 0)
  {
    push_int(0);
    return;
  }
  else
  {
    Pike_error("unable to parse, result code: %d!\n", res);
  }
}

/*! @decl int get_node_type()
 *! 
 */
PIKEFUN int get_node_type()
{
  if(THIS->object_data->reader == NULL)
  {
    Pike_error("no xmlReader!\n");
  }

  RETURN xmlTextReaderNodeType(THIS->object_data->reader);
}

/*! @decl int get_node_name()
 *! 
 */
PIKEFUN string get_node_name()
{
  xmlChar * c;

  if(THIS->object_data->reader == NULL)
  {
    Pike_error("no xmlReader!\n");
  }

  c = xmlTextReaderName(THIS->object_data->reader);
  if(c != NULL)
  {
    push_text(c);
    xmlFree(c);
  }
  else
    push_int(0);
}

/*! @decl int get_node_prefix()
 *! 
 */
PIKEFUN string get_node_prefix()
{
  xmlChar * c;

  if(THIS->object_data->reader == NULL)
  {
    Pike_error("no xmlReader!\n");
  }

  c = xmlTextReaderPrefix(THIS->object_data->reader);
  if(c != NULL)
  {
    push_text(c);
    xmlFree(c);
  }
  else
    push_int(0);
}

/*! @decl int get_node_prefix()
 *! 
 */
PIKEFUN string get_node_namespaceuri()
{
  xmlChar * c;

  if(THIS->object_data->reader == NULL)
  {
    Pike_error("no xmlReader!\n");
  }

  c = xmlTextReaderNamespaceUri(THIS->object_data->reader);
  if(c != NULL)
  {
    push_text(c);
    xmlFree(c);
  }
  else
    push_int(0);
}

/*! @decl int get_node_prefix()
 *! 
 */
PIKEFUN string get_node_localname()
{
  xmlChar * c;

  if(THIS->object_data->reader == NULL)
  {
    Pike_error("no xmlReader!\n");
  }

  c = xmlTextReaderLocalName(THIS->object_data->reader);
  if(c != NULL)
  {
    push_text(c);
    xmlFree(c);
  }
  else
    push_int(0);
}

/*! @decl int get_node_value()
 *! 
 */
PIKEFUN string get_node_value()
{
  xmlChar * c;

  if(THIS->object_data->reader == NULL)
  {
    Pike_error("no xmlReader!\n");
  }

  c = xmlTextReaderValue(THIS->object_data->reader);
  if(c != NULL)
  {
    push_text(c);
    xmlFree(c);
  }
  else
    push_int(0);
}

/*! @decl int get_node_string()
 *! 
 */
PIKEFUN string get_node_string()
{
  xmlChar * c;

  if(THIS->object_data->reader == NULL)
  {
    Pike_error("no xmlReader!\n");
  }

  c = xmlTextReaderReadString(THIS->object_data->reader);
  if(c != NULL)
  {
    push_text(c);
    xmlFree(c);
  }
  else
    push_int(0);
}

/*! @decl int get_node_inner_xml()
 *! 
 */
PIKEFUN string get_node_inner_xml()
{
  xmlChar * c;

  if(THIS->object_data->reader == NULL)
  {
    Pike_error("no xmlReader!\n");
  }

  c = xmlTextReaderReadInnerXml(THIS->object_data->reader);
  if(c != NULL)
  {
    push_text(c);
    xmlFree(c);
  }
  else
    push_int(0);
}

/*! @decl int get_node_outer_xml()
 *! 
 */
PIKEFUN string get_node_outer_xml()
{
  xmlChar * c;

  if(THIS->object_data->reader == NULL)
  {
    Pike_error("no xmlReader!\n");
  }

  c = xmlTextReaderReadOuterXml(THIS->object_data->reader);
  if(c != NULL)
  {
    push_text(c);
    xmlFree(c);
  }
  else
    push_int(0);
}

/*! @decl void create(string xml, string|void url, int|void options)
 *!
 */
PIKEFUN void create(string xml, string url, int options)
{
  xmlTextReaderPtr reader;
 
  reader = xmlReaderForMemory(xml->str, xml->len, url->str, 
               NULL, options);

  if(reader == NULL)
  {
    Pike_error("unable to get xmlReader\n");
  }

  THIS->object_data->reader = reader;

  pop_n_elems(args);
}

PIKEFUN void create(string xml)
{
  push_text("noname.xml");
  push_int(0);

  f_XMLReader_create(3);
}



INIT
{
  XMLREADER_OBJECT_DATA * dta;

  dta = 
	(XMLREADER_OBJECT_DATA*)malloc(sizeof(XMLREADER_OBJECT_DATA));
    if (!dta)
        Pike_error("init_xmlreader: Out of memory!\n");

    dta->reader = NULL;
    THIS->object_data = dta;
}

EXIT
{ 

  if(THIS->object_data->reader != NULL)
  {
    xmlFreeTextReader(THIS->object_data->reader);
  }
  if(THIS->object_data)
  {
    free(THIS->object_data);
  }
}
}

#endif /* HAVE_LIBXML_XMLREADER_H */
/*! @endclass
 */


/*! @endmodule
 */

/*! @endmodule
 */

/*! @endmodule
 */


void pike_init_xml2_xmlreader()
{
  INIT
}

void pike_exit_xml2_xmlreader()
{
  EXIT
}


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