/*
 *  SPL - The SPL Programming Language
 *  Copyright (C) 2004, 2005  Clifford Wolf <clifford@clifford.at>
 *
 *  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
 *
 *  example54.spl: simple example for modifying XML objects
 */

// SKIP_IF_NO_LIBXML2
// SKIP_IF_NO_REGEX
load "xml";

var xmldoc = xml_parse(<:>
	: <?xml version="1.0"?>
	: <swlist>
	:	<delme/><record year="1960">...</record><delme/>
	:	<delme/><record year="2004">...</record><delme/>
	:	<delme/><record year="2060">...</record><delme/>
	:	<delme/><record year="1980">...</record><delme/>
	:	<delme/><record year="2004">...</record><delme/>
	:	<delme/><record year="2005">...</record><delme/>
	:	<container/>
	: </swlist>
</>);

foreach[] i (xmldoc["//@year"].nodes)
	xmldoc[i] =~ s/2004/2005/;

xmldoc["//*[string(@year) = '1980']"].xml =
	"foo <hey>clifford's birthyear is 1980</hey> bar";

xmldoc["//*[string(@year) = '2060']"].innerxml =
	"this record is in the <b>future</b>!";

xmldoc["//*[string(@year) = '1960']"].innerxml =
	xmldoc["//*[string(@year) = '2060']"].innerxml =~ s/future/past/R;

delete xmldoc["//delme"];

xmldoc["//container"].add_xml_top	= "<middle1/>MID<middle2/>";
xmldoc["//container"].add_xml_bottom	= "<bottom1/>BOT<bottom2/>";
xmldoc["//container"].add_xml_top	= "<top1   />TOP<top2   />";
xmldoc["//container"].add_xml_before	= "<before1/>BEF<before2/>";
xmldoc["//container"].add_xml_after	= "<after1 />AFT<after2 />";

debug xml_dump(xmldoc);

