REBOL [
	Title:		"XML to RebXML Converter"
	Date:		08-Nov-2005
	Version:	1.2.0
	File:		%xml2rebxml.r
	Author:		"John Niclasen"
	Rights:		{Copyright © John Niclasen, NicomSoft 2005}
	Purpose:	{Convert XML to RebXML block structure.}

	Comment:	{
		Build from xml2txt.r and XML 1.0 DTD from www.w3.org.
	}

	History: [
		1.2.0	[08-11-2005 JN {Added suppport for " and ' in Attribute.
								Added preservation of comments.}]
		1.1.2	[06-11-2005 JN {Fixed bug with multi comments.}]
		1.1.1	[24-02-2005 JN {Changed EmptyElemTag from # to a slash: /}]
		1.1.0	[23-02-2005 JN {Added support for namespace-tags.
								Changed EmptyElemTag from "" to a number sign: #}]
		1.0.1	[31-01-2005 JN {Added "load mold" before returning output.
								Added replacements for ">", "<" and "&".}]
		1.0.0	[25-01-2005 JN {Created.}]
	]
	library: [
		level: 'intermediate
		platform: 'all
		type: 'tool
		domain: [markup parse xml]
		tested-under: none
		support: none
		license: 'BSD
		see-also: "rebxml2xml.r"
	]
]

output:	make block! 1000
context [

preserve-comments: false

lit-slash: to-lit-word "/"

block-begin: to word! "["
block-end: to word! "]"
attrs:	make block! 20
;output:	make block! 1000
input-str: none
att-data: data: temp: tag-name: att-name: enc-name: c: none

;-- Character Sets
joinset: func [cset chars] [insert copy cset chars]
diffset: func [cset chars] [remove/part copy cset chars]

space:	charset [#"^(09)" #"^(0A)" #"^(0D)" #" "]
char:	charset [#"^(09)" #"^(0A)" #"^(0D)" #" " - #"^(FF)"]
Letter: charset [
	#"A" - #"Z" #"a" - #"z"
	#"^(C0)" - #"^(D6)" #"^(D8)" - #"^(F6)" #"^(F8)" - #"^(FF)"
]
;Digit:	charset [#"0" - #"9"]
alpha-num:	joinset Letter "0123456789"		; need to allow: Digit
name-first:	joinset Letter "_:"

NameChar:	joinset alpha-num ".-_:"
data-chars:	diffset char "<"	; "&<"
Name:		[name-first any NameChar]
S:			[some space]

;-- XML Rules
document:		[prolog element to end]

AttValue:		["'" copy att-data to "'" skip | {"} copy att-data to {"} skip]

Comment:		["" (
	if preserve-comments [
		insert tail output join "