CoNNeTTivo
Ritorna al Sommario

Arte e Grafica

Arte In Movimento

Auto-aiuto informatico

CDA Anomalia

Comunicoscopio

CoNNeTTivo

Gr(A)fismo

Ocamlearn

Radar di Pace
Ocamlearn
Starting with PXP: XML modification
lunedì 31 marzo 2003





NELLA STESSA RUBRICA :
>7 marzo 2003
>5 marzo 2003
PAROLE CHIAVE ASSOCIATE :





ARTICOLI CON LO STESSO TEMA :


Here is an example for starting using PXP, the Polymorphic XML Parser by Gerd Stolpmann.

XML MODIFICATION

(*
  Sample changes to a PXP (an OCaml XML parser) XML tree

Copyright (C) <2003> Stefano Zacchiroli <zack@cs.unibo.it>

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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *)

open Pxp_document;; open Pxp_dtd;; open Pxp_types;; open Pxp_yacc;;

(*z facility function to parse a well formed (validation is not performed!) XML document from the file named in ’fname’ argument. It returns a PXP "document". *) let parse_xml fname = parse_wfdocument_entity default_config (from_file fname) default_spec in (*z use the above function to parse XML document contained in file passed on command line *) let document = parse_xml Sys.argv.(1) in (*z get root element of the above XML document, this is the beginning of the XML tree *) let root = document#root in (*z find the first "c" node of the XML tree, find is performed using "find_element" function telling it to depply travel the XML tree ’root’ *) let c_node = find_element deeply:true "c" root in (*z get data child of ’c’ node. Note that we use here the assumption that first child of ’c’ node is a data node *) let c_data = c_node#nth_node 0 in (*z change ’c’ node string data to a sample string *) c_data#set_data "Hello, PXP World!";

(*z dump (modified) xml output to stdout *) root#write (`Out_channel stdout) `Enc_utf8

© Stefano ’’Zack’’ Zacchiroli GNU FDL + GPL 2003

CoNNeTTivo   



© 2003 realizzato e concepito da ernestor + arlok + oSi + Z.
Questo sito usa PHP e mySQL ed è realizzato con software in licenza GNU/GPL.
Tutti i testi contenuti in questo sito sono COPYRIGHT dei loro autori.

fil XML