CREATE TABLE xml_objects (xml_object_id int NOT NULL,state int NOT NULL,path varchar (200) NOT NULL,file_name varchar (50) NOT NULL,title varchar (255),reference int, CONSTRAINT PK_xml_objects PRIMARY KEY  (xml_object_id))
GO


CREATE TABLE xml_elements (
	xml_element_id int NOT NULL ,
	xml_object_id int NOT NULL ,
	left_index int NOT NULL ,
	right_index int NOT NULL ,
	element_name varchar (255) NOT NULL ,
	xml_parent_id int ,
	CONSTRAINT PK_xml_elements PRIMARY KEY  
	(
		xml_element_id
	),
	CONSTRAINT FK_xml_elements_xml_objects FOREIGN KEY 
	(
		xml_object_id
	) REFERENCES xml_objects (
		xml_object_id
	)
)
GO

 CREATE  INDEX IX_xml_elements ON xml_elements(left_index)
GO

 CREATE  INDEX IX_xml_elements_1 ON xml_elements(right_index)
GO

 CREATE  INDEX IX_xml_elements_2 ON xml_elements(element_name)
GO


CREATE TABLE xml_attributes (
	xml_attribute_id int NOT NULL ,
	xml_element_id int NOT NULL ,
	name varchar (250) NOT NULL ,
	value varchar (250) NOT NULL ,
	CONSTRAINT PK_xml_attributes PRIMARY KEY  
	(
		xml_attribute_id
	),
	CONSTRAINT FK_xml_attributes_xml_elements FOREIGN KEY 
	(
		xml_element_id
	) REFERENCES xml_elements (
		xml_element_id
	)
)
GO

 CREATE  INDEX IX_xml_attributes ON xml_attributes(name)
GO

 CREATE  INDEX IX_xml_attributes_1 ON xml_attributes(value)
GO


CREATE TABLE xml_cdata (
	xml_cdata_id int NOT NULL ,
	xml_element_id int NOT NULL ,
	cdata LONG VARCHAR NOT NULL ,
	CONSTRAINT PK_xml_cdata PRIMARY KEY  
	(
		xml_cdata_id
	),
	CONSTRAINT FK_xml_cdata_xml_elements FOREIGN KEY 
	(
		xml_element_id
	) REFERENCES xml_elements (
		xml_element_id
	)
)
GO

CREATE TABLE xml_tokens ( 
xml_token_id int NOT NULL, 
tertiary_id int NOT NULL,
secondary_id int NOT NULL,
primary_id int NOT NULL,
token varchar (64) NOT NULL ,
CONSTRAINT PK_xml_tokens PRIMARY KEY  (xml_token_id)
)
GO


/* xml_word_id indicates order */
CREATE TABLE xml_words (
xml_word_id int NOT NULL, 
xml_cdata_id int NOT NULL, 
xml_element_id int NOT NULL, 

xml_token_id int NOT NULL,
pos int NOT NULL,
flags int NOT NULL,

CONSTRAINT PK_xml_words PRIMARY KEY ( xml_word_id ), 
CONSTRAINT FK_xml_words_xml_cdata FOREIGN KEY ( xml_cdata_id) REFERENCES xml_cdata ( xml_cdata_id	),
CONSTRAINT FK_xml_words_xml_tokens FOREIGN KEY (xml_token_id) REFERENCES xml_tokens (xml_token_id))
GO


CREATE  INDEX IX_xml_words ON xml_words(xml_token_id)
GO



