#!/usr/bin/env ascript
import(xml)

lambda {
	parser = xml.parser {
		StartElement(obj, elem) = {
			//printf("%s\n", elem)
			//printf("%s %s %s\n", elem.name, elem.tostring(), elem.children.tostring())
			//for (att in atts) {
			//	printf(" %s='%s'", att[0], att[1])
			//}
			//println()
		}
		EndElement(obj, name:string) = {
			//println(name)
		}
		CharacterData(obj, text:string) = {
			//print(text)
		}
		ProcessingInstruction(obj, target:string, data:string) = {
		}
		Comment(obj, data:string) = {
		}
		StartCdataSection(obj) = {
		}
		EndCdataSection(obj) = {
		}
		Default(obj, text:string) = {
		}
		DefaultExpand(obj, text:string) = {
		}
		SkippedEntity(obj, entityName:string, isParameterEntity:boolean) = {
		}
		StartNamespaceDecl(obj, prefix:string, uri:string) = {
		}
		EndNamespaceDecl(obj, prefix:string) = {
		}
		XmlDecl(obj, version:string, encoding:string, standalone?:boolean) = {
			printf("%s %s %s\n", version, encoding, standalone)
		}
		StartDoctypeDecl(obj, doctypeName:string, systemId:string,
									publicId:string, hasInternalSubset:boolean) = {
		}
		EndDoctypeDecl(obj) = {
		}
		ElementDecl(obj, name:string, type:symbol) = {
		}
		AttlistDecl(obj, elemName:string, attName:string, attType:string,
												default:string, isRequired:boolean) = {
		}
		EntityDecl(obj, entityName:string, isParameterEntity:boolean, value:string,
				base:string, systemId:string, publicId:string, notationName:string) = {
		}
		NotationDecl(obj, notationName:string, base:string,
												systemId:string, publicId:string) = {
		}
		NotStandalone(obj) = {
		}
	}
	parser.parse(nil, open("document.xsl"));
}()
lambda {
	e = xml.element
	elem = e("hoge", attr => "aaa", attr_2 => "bbb") {
		e("foo") {
			"text"
			e("bar")
			"fjdkfjdsjfkldsj fjdkjfdsa fjdskfjds fjkfdsjfkds"
			e("bar")
			e("bar")
			e("bar")
			e("bar")
			e("bar")
			e("bar")
		}
		e("foo")
	}
	println(elem.format())
}()
lambda {
	e = xml.read(open("document.xsl"))
	println(e.name)
	#println(e.children::name, " ", e.children::get("match"))
}()
