diff -Naur orig/XML-Validator-Schema/Schema/AttributeNode.pm XML-Validator-Schema/Schema/AttributeNode.pm
--- orig/XML-Validator-Schema/Schema/AttributeNode.pm	2005-10-22 06:06:36.000000000 -0700
+++ XML-Validator-Schema/Schema/AttributeNode.pm	2006-02-01 15:20:49.000000000 -0800
@@ -17,8 +17,11 @@
 =cut
 
 sub parse {
-    my ($pkg, $data) = @_;
-    my $self = $pkg->new();
+    my ($pkg, $data, $schema, $parser) = @_;
+    my $self = $pkg->new({attributes => {
+	schema => $schema, 
+	parser => $parser
+	}});
 
     # squirl away data for latter use
     $self->{data} = $data;
@@ -30,7 +33,7 @@
     my ($self) = shift;
 
     # create a new attribute object and return it
-    my $attr = XML::Validator::Schema::Attribute->parse($self->{data});
+    my $attr = XML::Validator::Schema::Attribute->parse($self->{data}, $self->attributes->{schema}, $self->attributes->{parser});
 
     # copy in type info if available
     $attr->{type} = $self->{type} if $self->{type};
diff -Naur orig/XML-Validator-Schema/Schema/Attribute.pm XML-Validator-Schema/Schema/Attribute.pm
--- orig/XML-Validator-Schema/Schema/Attribute.pm	2005-10-22 06:06:33.000000000 -0700
+++ XML-Validator-Schema/Schema/Attribute.pm	2006-02-01 15:20:49.000000000 -0800
@@ -22,13 +22,16 @@
 
 # create an attribute based on the contents of an element hash
 sub parse {
-    my ($pkg, $data) = @_;
+    my ($pkg, $data, $schema, $parser) = @_;
     my $self = $pkg->new();
 
     my $name = _attr($data, 'name');
-    $self->{name} = $name if $name;
+    if ($name) {
+	$name = $parser->targeted_attribute_name($name);
+	$self->{name} = $name;
+    }
 
-    my $ref  = _attr($data, 'ref');
+    my $ref  = $parser->namespaced_name($data, 'ref');
     if ($ref) {
         _err("Illegal combination of 'ref' and 'name' in <attribute>.")
           if $name;
@@ -39,7 +42,7 @@
     _err("Found <attribute> with neither 'name' nor 'ref'.")
       unless $name or $ref;
 
-    my $type_name = _attr($data, 'type');
+    my $type_name = $parser->namespaced_name($data, 'type');
     if ($type_name) {
         $self->{unresolved_type} = 1;
         $self->{type_name} = $type_name;
diff -Naur orig/XML-Validator-Schema/Schema/ComplexTypeNode.pm XML-Validator-Schema/Schema/ComplexTypeNode.pm
--- orig/XML-Validator-Schema/Schema/ComplexTypeNode.pm	2005-10-22 06:06:37.000000000 -0700
+++ XML-Validator-Schema/Schema/ComplexTypeNode.pm	2006-02-01 15:20:49.000000000 -0800
@@ -20,8 +20,9 @@
     $self->SUPER::compile();
 
     # register in the library if this is a named type
-    $self->root->{type_library}->add(name => $self->{name},
-                                     obj  => $self)
+    $self->attributes->{schema}{type_library}->add(name => $self->{name},
+                                     obj  => $self, 
+				     parser => $self->attributes->{parser})
       if $self->{name};
 }
 
diff -Naur orig/XML-Validator-Schema/Schema/ElementNode.pm XML-Validator-Schema/Schema/ElementNode.pm
--- orig/XML-Validator-Schema/Schema/ElementNode.pm	2005-10-22 06:06:39.000000000 -0700
+++ XML-Validator-Schema/Schema/ElementNode.pm	2006-02-01 16:21:40.000000000 -0800
@@ -19,15 +19,19 @@
 # create a node based on the contents of an <element> found in the
 # schema document
 sub parse {
-    my ($pkg, $data) = @_;
-    my $self = $pkg->new();
+    my ($pkg, $data, $schema, $parser) = @_;
+    my $self = $pkg->new({attributes => {
+	schema => $schema, 
+	parser => $parser
+	}});
 
     my $name = _attr($data, 'name');
     _err('Found element without a name.')
       unless $name;
+    $name = $self->attributes->{parser}->targeted_element_name($name);
     $self->name($name);
 
-    my $type_name = _attr($data, 'type');
+    my $type_name = $self->attributes->{parser}->namespaced_name($data, 'type');
     if ($type_name) {
         $self->{unresolved_type} = 1;
         $self->{type_name} = $type_name;
@@ -84,10 +88,11 @@
 # check if a given name is a legal child, and return it if it is
 sub check_daughter {
     my ($self, $name) = @_;
-    my ($daughter) = grep { $_->{name} eq $name } ($self->daughters);
+    my %allowed = map { $_->{name}, $_ } $self->daughters;
+    my $daughter = $allowed{$name};
 
     # doesn't even exist?
-    _err("Found unexpected <$name> inside <$self->{name}>.  This is not a valid child element.")
+    _err("Found unexpected <$name> inside <$self->{name}>, expected one of (".join(',', keys %allowed).')')
       unless $daughter;
 
     # push on
@@ -97,18 +102,21 @@
     $self->{model}->check_model($self->{name}, $self->{memory})
       if $self->{model};
 
-    # does this daughter have a valid type?  if not, attempt to elaborate
-    if ($daughter->{unresolved_type}) {
-        $self->root->complete_type($daughter);
-        ($daughter) = grep { $_->{name} eq $name } ($self->daughters);
+    my $last = 0; # Re-run until resolution doesn't change anything.
+    while ($last != $daughter) {
+	$last = $daughter;
+	# does this daughter have a valid type?  if not, attempt to elaborate
+	if ($daughter->{unresolved_type}) { die;
+	    $self->root->complete_type($daughter);
+	    ($daughter) = grep { $_->{name} eq $name } ($self->daughters);
+	}
+	
+	# is this daughter a dangling ref?  if so, complete it
+	if ($daughter->{unresolved_ref}) { die;
+	    $self->root->complete_ref($daughter);
+	    ($daughter) = grep { $_->{name} eq $name } ($self->daughters);
+	}
     }
-    
-    # is this daughter a dangling ref?  if so, complete it
-    if ($daughter->{unresolved_ref}) {
-        $self->root->complete_ref($daughter);
-        ($daughter) = grep { $_->{name} eq $name } ($self->daughters);
-    }
-
     return $daughter;
 }
 
@@ -136,11 +144,12 @@
 
         # attributes in http://www.w3.org/2000/xmlns/ are namespace
         # declarations and don't concern us
-        next if $attr->{NamespaceURI} eq 'http://www.w3.org/2000/xmlns/';
+        next if $attr->{NamespaceURI} eq 'http://www.w3.org/2000/xmlns/' or
+	    $attr->{NamespaceURI} eq '' && $attr->{LocalName} eq 'xmlns';
 
-        my $name = $attr->{LocalName};
+        my $name = "{$attr->{NamespaceURI}}$attr->{LocalName}";
         my $obj = $allowed{$name}; 
-        _err("Illegal attribute '$name' found in <$self->{name}>.")
+        _err("Illegal attribute '$name' found in <$self->{name}>, expected one of (".join(',', keys %allowed).')')
           unless $obj;
         $saw{$name} = 1;
         
@@ -168,12 +177,21 @@
 sub compile {
     my $self = shift;
 
+#    $self->register_element
+#      if  $self->{name} && $self->mother->is_root;
     if ($self->daughters and 
         ($self->daughters)[0]->isa('XML::Validator::Schema::ModelNode')) {
         ($self->daughters)[0]->compile;
     }
 }
 
+sub register_element {
+    my $self = shift;
+    $self->attributes->{schema}{element_library}->add(name => $self->{name},
+                                     obj  => $self, 
+				     parser => $self->attributes->{parser});
+}
+
 # forget about the past
 sub clear_memory {
     @{$_[0]->{memory}} = () if $_[0]->{memory};
diff -Naur orig/XML-Validator-Schema/Schema/ElementRefNode.pm XML-Validator-Schema/Schema/ElementRefNode.pm
--- orig/XML-Validator-Schema/Schema/ElementRefNode.pm	2005-10-22 06:06:40.000000000 -0700
+++ XML-Validator-Schema/Schema/ElementRefNode.pm	2006-02-01 15:20:49.000000000 -0800
@@ -19,21 +19,24 @@
 =cut
 
 sub parse {
-    my ($pkg, $data) = @_;
-    my $self = $pkg->new();
+    my ($pkg, $data, $schema, $parser) = @_;
+    my $self = $pkg->new({attributes => {
+	schema => $schema, 
+	parser => $parser
+	}});
 
-    my $ref = _attr($data, 'ref');
+    my $ref = $self->attributes->{parser}->namespaced_name($data, 'ref');
     croak("Why did you create an ElementRefNode if you didn't have a ref?")
       unless $ref;
     $self->{unresolved_ref} = 1;
     $self->name($ref);
 
-    my $name = _attr($data, 'name');
+    my $name = $self->attributes->{parser}->namespaced_name($data, 'name');
     _err("Found <element> with illegal combination of 'ref' and 'name' ".
          "attributes.")
       if $name;
 
-    my $type_name = _attr($data, 'type');
+    my $type_name = $self->attributes->{parser}->namespaced_name($data, 'type');
     _err("Found <element> with illegal combination of 'ref' and 'type' ".
          "attributes.")
       if $type_name;
@@ -54,5 +57,9 @@
     return $self;
 }
 
+sub register_element {
+    # do nothing -- disable's parent classes behavior of registering self.
+}
+
 1;
 
diff -Naur orig/XML-Validator-Schema/Schema/Library.pm XML-Validator-Schema/Schema/Library.pm
--- orig/XML-Validator-Schema/Schema/Library.pm	2005-10-22 06:06:44.000000000 -0700
+++ XML-Validator-Schema/Schema/Library.pm	2006-02-01 16:07:32.000000000 -0800
@@ -15,6 +15,9 @@
 
 =cut
 
+use constant OBJ => 0;
+use constant LOC => 1;
+
 sub new {
     my $pkg = shift;
     my $self = bless({@_}, $pkg);
@@ -33,7 +36,7 @@
     my @ret;
     foreach my $ns (keys %{$self->{stacks}}) {
         foreach my $name (keys %{$self->{$ns}}) {
-            push @ret, $self->{stacks}{$ns}{$name};
+            push @ret, $self->{stacks}{$ns}{$name}[OBJ];
         }
     }
     return @ret;
@@ -43,26 +46,35 @@
     my ($self, %arg) = @_;
     croak("Missing required name paramter.") unless $arg{name};
 
-    # HACK: fix when QName resolution works
-    $arg{name} =~ s!^[^:]*:!!;
-    $arg{ns} ||= XSD;
-
-    return $self->{stacks}{$arg{ns}}{$arg{name}};
+    my ($ns, $lname) = &_resolve(%arg);
+    return exists $self->{stacks}{$ns} ? $self->{stacks}{$ns}{$lname}[OBJ] : undef;
 }
 
 sub add {
     my ($self, %arg) = @_;
     croak("Missing required name paramter.") unless $arg{name};
     croak("Missing required obj paramter.") unless $arg{obj};
-    
-    # HACK: fix when QName resolution works
-    $arg{name} =~ s!^\w+:!!;
-    $arg{ns} ||= XSD;
-
-    _err("Illegal attempt to redefine $self->{what} '$arg{name}' ".
-         "in namespace '$arg{ns}'")
-      if exists $self->{stacks}{$arg{ns}}{$arg{name}};
-    $self->{stacks}{$arg{ns}}{$arg{name}} = $arg{obj};
+
+    my $location = $arg{parser}->add_error_context($self->{what});
+    my ($ns, $lname) = &_resolve(%arg);
+
+    _err("Illegal attempt to redefine $self->{what} '$lname' ".
+         "in namespace '$ns' $self->{stacks}{$ns}{$lname}[LOC]")
+      if exists $self->{stacks}{$ns}{$lname};
+    $self->{stacks}{$ns}{$lname} = [$arg{obj}, $location];
+}
+
+sub _resolve {
+    my (%arg) = @_;
+    my $lname = $arg{name};
+    my $ns;
+    if (1 || $arg{parser}{qualified_elements}) { # !!! HACK
+	$lname =~ s!^\{([^\}]*)\}!!;
+	$ns = $1;
+    } else {
+	$ns = XSD;
+    }
+    return ($ns, $lname);
 }
 
 1;
diff -Naur orig/XML-Validator-Schema/Schema/Node.pm XML-Validator-Schema/Schema/Node.pm
--- orig/XML-Validator-Schema/Schema/Node.pm	2005-10-22 06:06:46.000000000 -0700
+++ XML-Validator-Schema/Schema/Node.pm	2006-02-03 00:27:31.000000000 -0800
@@ -33,5 +33,36 @@
     return 1;
 }
 
+sub complete_all {
+    my ($self) = @_;
+    if (my $newSelf = $self->complete_one()) {
+	foreach my $daughter ($self->daughters) {
+	    $daughter->complete_all();
+	}
+	$self = $newSelf;
+    }
+    return $self;
+}
+
+sub complete_one {
+    my ($self) = @_;
+    # Re-run until resolution doesn't change anything.
+    for (my $last = 0; $last != $self; ) {
+	$last = $self;
+	# does this daughter have a valid type?  if not, attempt to elaborate
+	if ($self->{unresolved_type}) {
+	    delete $self->{unresolved_type};
+	    $self = $self->root->complete_type($self);
+	}
+	
+	# is this daughter a dangling ref?  if so, complete it
+	if ($self->{unresolved_ref}) {
+	    delete $self->{unresolved_ref};
+	    $self = $self->root->complete_ref($self);
+	}
+    }
+    return $self;
+}
+
 1;
 
diff -Naur orig/XML-Validator-Schema/Schema/Parser.pm XML-Validator-Schema/Schema/Parser.pm
--- orig/XML-Validator-Schema/Schema/Parser.pm	2005-10-22 06:06:47.000000000 -0700
+++ XML-Validator-Schema/Schema/Parser.pm	2006-02-01 16:22:46.000000000 -0800
@@ -14,7 +14,8 @@
 =cut
 
 use base 'XML::SAX::Base';
-use XML::Validator::Schema::Util qw(_attr _err);
+use XML::Validator::Schema::Util qw(_attr _err XSD);
+use XML::NamespaceSupport;
 
 sub new {
     my $pkg  = shift;
@@ -23,15 +24,55 @@
 
     # start with a dummy root node and an empty stack of elements
     $self->{node_stack} = $self->{schema}{node_stack};
+    $self->{NSHelper} = XML::NamespaceSupport->new({xmlns => 1});
+    $self->{qualified_elements} = 0;
+    $self->{qualified_attributes} = 0;
+    $self->{startANY} = 0;
+    $self->{targetNamespace} = '';
 
     return $self;
 }
 
+#
+# SAX2 functions
+#
+sub set_document_locator {
+    my ($self, $locator) = @_;
+    $self->{schema}->set_schema_document_locator($locator);
+}
+
+sub start_prefix_mapping {
+    my ($self, $mapping) = @_;
+    $self->{NSHelper}->declare_prefix($mapping->{Prefix},
+				      $mapping->{NamespaceURI});
+}
+
+sub end_prefix_mapping {
+    my ($self, $mapping) = @_;
+    $self->{NSHelper}->undeclare_prefix($mapping->{Prefix});
+}
+
 sub start_element {
     my ($self, $data) = @_;
+    eval {
+	$self->start_element1($data);
+    }; if ($@) {
+	$@ = $self->add_error_context($@);
+	die $@;
+    }
+}
+
+sub start_element1 {
+    my ($self, $data) = @_;
     my $node_stack = $self->{node_stack};
     my $mother = @$node_stack ? $node_stack->[-1] : undef;
     my $name = $data->{LocalName};
+    my $namespace = $data->{NamespaceURI};
+    # @args: common arguments used for most calls
+    my @args = ($data, $self->{schema}, $self);
+
+    _err("W3C XML Schemas must be in the ".XSD." namespace (found $namespace).")
+      if  $namespace && $namespace ne XSD && !$self->{inAppinfo};
 
     # make sure schema comes first
     _err("Root element must be <schema>, fount <$name> instead.")
@@ -39,31 +80,42 @@
     
     # starting up?
     if ($name eq 'schema') {
-        my $node = XML::Validator::Schema::RootNode->new;
-        $node->name('<<<ROOT>>>');
-        push(@$node_stack, $node);
 
-        # make sure elementFormDefault and attributeFormDefault are
-        # 'unqualified' if declared since that's all we're up to
-        for (qw(elementFormDefault attributeFormDefault)) {
-            my $a = _attr($data, $_);
-            _err("$_ in <schema> must be 'unqualified', ".
-                        "'qualified' is not supported.")
-              if $a and $a ne 'unqualified';
+        # set up resolvers for qualified elementFormDefault and
+	# attributeFormDefault.
+	my %qualifiers = qw(elementFormDefault qualified_elements
+			    attributeFormDefault qualified_attributes);
+        while (my ($attr, $my_name) = each %qualifiers) {
+            my $a = _attr($data, $attr);
+	    if ($a) {
+		_err("$_ in <schema> must be 'qualified' or 'unqualified'.")
+		  if  $a ne 'qualified' and $a ne 'unqualified';
+		$self->{$my_name} = 1
+		  if  $a eq 'qualified';
+	    }
         }
 
-        # ignoring targetSchema intentionally.  With both Defaults
-        # unqualified there isn't much point looking at it.
+	if (my $ts = _attr($data, 'targetNamespace')) {
+	    _err("targetNamespace makes no sense if neither elementFormDefault or attributeFormDefault is qualified (found $ts).")
+	      if  !$self->{qualified_elements} && !$self->{qualified_attributes};
+	    $self->{targetNamespace} = $ts;
+	}
+
+        my $node = XML::Validator::Schema::RootNode->new({attributes => 
+				  {schema => $self->{schema}, 
+				   parser => $self}});
+        $node->name('<<<ROOT>>>');
+        push(@$node_stack, $node);
     }
 
     # handle element declaration
     elsif ($name eq 'element') {      
         my $node;
         if (_attr($data, 'ref')) {
-            $node = XML::Validator::Schema::ElementRefNode->parse($data);
+            $node = XML::Validator::Schema::ElementRefNode->parse(@args);
         } else {
             # create a new node for the element
-            $node = XML::Validator::Schema::ElementNode->parse($data);        
+            $node = XML::Validator::Schema::ElementNode->parse(@args);
         }
 
         # add to current node's daughter list and become the current node
@@ -78,7 +130,7 @@
           if not $name and $mother->is_root;
 
         # parse it into an AttributeNode and tell Mom about it
-        my $node = XML::Validator::Schema::AttributeNode->parse($data);
+        my $node = XML::Validator::Schema::AttributeNode->parse(@args);
         $mother->add_daughter($node);
         push @$node_stack, $node;
     }
@@ -96,7 +148,7 @@
           unless $mother->{simple_content};
 
         # extract simpleType from base
-        my $base = _attr($data, 'base');
+        my $base = $self->namespaced_name($data, 'base');
         _err("Found <extension> without required 'base' attribute.")
           unless $base;
         $mother->{type_name} = $base;
@@ -104,14 +156,14 @@
     }
 
     elsif ($name eq 'simpleType') {
-        my $name = _attr($data, 'name');
+        my $name = $self->namespaced_name($data, 'name');
         if ($name) {
             _err("Named simpleType must be global.")
               unless $mother->is_root;
 
             # this is a named type, parse it into an SimpleTypeNode 
             # and tell Mom about it
-            my $node = XML::Validator::Schema::SimpleTypeNode->parse($data);
+            my $node = XML::Validator::Schema::SimpleTypeNode->parse(@args);
             $mother->add_daughter($node);
             push @$node_stack, $node;
 
@@ -124,7 +176,7 @@
 
             # this is a named type, parse it into an SimpleTypeNode 
             # and tell Mom about it
-            my $node = XML::Validator::Schema::SimpleTypeNode->parse($data);
+            my $node = XML::Validator::Schema::SimpleTypeNode->parse(@args);
             $mother->add_daughter($node);
             push @$node_stack, $node;
 
@@ -155,14 +207,14 @@
     }
 
     elsif ($name eq 'complexType') {
-        my $name = _attr($data, 'name');
+        my $name = $self->namespaced_name($data, 'name');
         if ($name) {
             _err("Named complexType must be global.")
               unless $mother->is_root;
 
             # this is a named type, parse it into an ComplexTypeNode 
             # and tell Mom about it
-            my $node = XML::Validator::Schema::ComplexTypeNode->parse($data);
+            my $node = XML::Validator::Schema::ComplexTypeNode->parse(@args);
             $mother->add_daughter($node);
             push @$node_stack, $node;
 
@@ -193,6 +245,19 @@
         # skip
     }
 
+    elsif ($name eq 'import' || $name eq 'include') {
+        my $location = _attr($data, 'schemaLocation');
+	croak("not sure what to do without a schemaLocation")
+	  if  !$location;
+	$self->{schema}->parse_schema($location);
+    }
+
+    elsif ($name eq 'appinfo') {
+	croak("recursive appinfos not supported")
+	  if  $self->{inAppinfo};
+        $self->{inAppinfo} = @$node_stack;
+    }
+
     else {
         # getting here is bad news
         _err("Unrecognized element '<$name>' found.");
@@ -201,17 +266,29 @@
 
 sub end_element {
     my ($self, $data) = @_;
+    eval {
+	$self->end_element1($data);
+    }; if ($@) {
+	$@ = $self->add_error_context($@);
+	die $@;
+    }
+}
+
+sub end_element1 {
+    my ($self, $data) = @_;
     my $node_stack = $self->{node_stack};
     my $node = $node_stack->[-1];
     my $name = $data->{LocalName};
 
     # all done?
     if ($name eq 'schema') {
-        croak("Module done broke, man.  That element stack ain't empty!")
+        _err("Module done broke, man.  That element stack ain't empty!")
           unless @$node_stack == 1;
 
         # finish up
         $node_stack->[-1]->compile();
+	$node_stack->[-1]->complete_all();
+	$self->{schema}->add_root($node_stack->[-1]);
 
         return;
     }
@@ -259,8 +336,10 @@
 
         if ($name and $mother->is_root) {
             # named attribute in the root gets added to the attribute library
-            $mother->{attribute_library}->add(name => $name,
-                                              obj  => $attr);
+            $self->{schema}{attribute_library}->add(name => $name,
+                                              obj  => $attr, 
+					      schema => $self->{schema}, 
+					      parser => $self);
         } else {
             # attribute in an element goes on the attr array
             push @{$mother->{attr} ||= []}, $attr;
@@ -271,8 +350,52 @@
         return;
     }
         
+    if ($name eq 'appinfo') {
+        $self->{inAppinfo} = 0;
+	return;
+    }
+
     # it's ok to fall off the end here, not all elements recognized in
     # start_element need finalizing.
 }
 
+#
+# support functions
+#
+sub add_error_context {
+    my ($self, $msg) = @_;
+    my $locator = $self->{schema}{locator};
+    my $context = " [Id: $locator->{SystemId}, Ln: $locator->{LineNumber}, Col: $locator->{ColumnNumber}]";
+    $msg =~ s/$/$context/;
+    return $msg;
+}
+
+sub targeted_element_name {
+    my ($self, $name) = @_;
+    return $self->{qualified_elements} ? "{$self->{targetNamespace}}$name" : "{}$name";
+}
+
+
+sub targeted_attribute_name {
+    my ($self, $name) = @_;
+    return $self->{qualified_attributes} ? "{$self->{targetNamespace}}$name" : "{}$name";
+}
+
+sub namespaced_name {
+    my ($self, $data, $name) = @_;
+    if (my $ret = _attr($data, $name)) {
+
+	my ($ns, $prefix, $lname) = ('', '', $ret);
+	if ($self->{NSHelper}) {
+	    ($ns, $prefix, $lname) = $self->{NSHelper}->process_element_name($ret);
+	} else {
+	    $lname = $name;
+	}
+	$ns ||= ''; $prefix ||= '';
+	return "{$ns}$lname";
+
+    }
+    return undef;
+}
+
 1;
diff -Naur orig/XML-Validator-Schema/Schema/RootNode.pm XML-Validator-Schema/Schema/RootNode.pm
--- orig/XML-Validator-Schema/Schema/RootNode.pm	2005-10-22 06:07:11.000000000 -0700
+++ XML-Validator-Schema/Schema/RootNode.pm	2006-02-01 16:13:46.000000000 -0800
@@ -20,28 +20,17 @@
 
 =cut
 
-sub new {
-    my $pkg = shift;
-    my $self = $pkg->SUPER::new(@_);
-
-    # start up with empty libraries
-    $self->{type_library}      = XML::Validator::Schema::TypeLibrary->new;
-    $self->{element_library}   = XML::Validator::Schema::ElementLibrary->new;
-    $self->{attribute_library} = XML::Validator::Schema::AttributeLibrary->new;
-
-    return $self;
-}
-
 # finish typing and references
 sub compile {
     my $self = shift;
-    my $element_library = $self->{element_library};
 
     # put global elements into the library (could move this to ::ElementNode)
     foreach my $d ($self->daughters) {
         if (ref($d) eq 'XML::Validator::Schema::ElementNode') {
-            $element_library->add(name => $d->{name},
-                                  obj  => $d);
+            $self->attributes->{schema}{element_library}->add(name => $d->{name},
+                                  obj  => $d, 
+				  schema => $self->attributes->{schema}, 
+				  parser => $self->attributes->{parser});
         }
     }
 
@@ -68,10 +57,10 @@
     }
 
     # all done unless unresolved
-    return unless $ref->{unresolved_ref};
+    return undef unless $ref->{unresolved_ref};
 
     my $name = $ref->{name};
-    my ($element) = $self->{element_library}->find(name => $ref->{name});
+    my ($element) = $self->attributes->{schema}{element_library}->find(name => $ref->{name}, parser => $self->attributes->{parser});
     _err("Found unresolved reference to element '$name'")
       unless $element;
 
@@ -80,12 +69,11 @@
     # replace the current element
     $ref->replace_with($element->copy_at_and_under);
 
-    return;
+    return $element;
 }
 
 sub complete_type {
     my ($self, $element) = @_;
-    my $library = $self->{type_library};
 
     # handle any unresolved attribute types
     if ($element->{attr}) {
@@ -94,24 +82,25 @@
     }
 
     # all done unless unresolved
-    return unless $element->{unresolved_type};
+    return undef unless $element->{unresolved_type};
 
     # get type data
     my $type_name = $element->{type_name};
-    my $type = $library->find(name => $type_name);
+    my $type = $self->attributes->{schema}{type_library}->find(name => $type_name, parser => $self->attributes->{parser});
 
     # isn't there?
-    _err("Element '<$element->{name}>' has unrecognized type '$type_name'.") 
+    $self->attributes->{schema}{type_library}->find(name => $type_name, parser => $self->attributes->{parser}), _err("Element '<$element->{name}>' has unrecognized type '$type_name'.") 
       unless $type;
 
 
+    my $new_node = $element;
     if ($type->isa('XML::Validator::Schema::ComplexTypeNode')) {
         # can't have daughters for this to work
         _err("Element '<$element->{name}>' is using a named complexType and has sub-elements of its own.  That's not supported.")
           if $element->daughters;
     
         # replace the current element with one based on the complex node
-        my $new_node = $type->copy_at_and_under;
+        $new_node = $type->copy_at_and_under;
         $new_node->name($element->{name});
         $new_node->{attr} = [ @{ $new_node->{attr} || [] }, 
                               @{ $element->{attr} || [] } ];
@@ -127,12 +116,13 @@
 
     # fixed it
     delete $element->{unresolved_type};
+    return $new_node;
 }
 
 sub complete_attr_type {
     my ($self, $attr) = @_;
 
-    my $type = $self->{type_library}->find(name => $attr->{type_name});
+    my $type = $self->attributes->{schema}{type_library}->find(name => $attr->{type_name}, parser => $self->attributes->{parser});
     _err("Attribute '<$attr->{name}>' has unrecognized ".
          "type '$attr->{type_name}'.")
       unless $type;
@@ -144,7 +134,7 @@
 sub complete_attr_ref {
     my ($self, $ref) = @_;
 
-    my $attr = $self->{attribute_library}->find(name => $ref->{name});
+    my $attr = $self->attributes->{schema}{attribute_library}->find(name => $ref->{name}, parser => $self->attributes->{parser});
     _err("Attribute reference '$ref->{name}' not found.")
       unless $attr;
     
diff -Naur orig/XML-Validator-Schema/Schema/SimpleTypeNode.pm XML-Validator-Schema/Schema/SimpleTypeNode.pm
--- orig/XML-Validator-Schema/Schema/SimpleTypeNode.pm	2005-10-22 06:07:14.000000000 -0700
+++ XML-Validator-Schema/Schema/SimpleTypeNode.pm	2006-02-01 15:20:49.000000000 -0800
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use XML::Validator::Schema::Util qw(_attr _err);
+use XML::Validator::Schema::Util qw(_attr _err XSD);
 use Carp qw(confess);
 
 =head1 NAME
@@ -17,17 +17,21 @@
 =cut
 
 # Hash mapping facet names to allowable values
-our %FACET_VALUE = (length =>         "nonNegativeInteger",
-                    minLength =>      "nonNegativeInteger",
-                    maxLength =>      "nonNegativeInteger",
-                    totalDigits =>    "positiveInteger",
-                    fractionDigits => "nonNegativeInteger");
+our $XSD = XSD;
+our %FACET_VALUE = (length =>         "{$XSD}nonNegativeInteger",
+                    minLength =>      "{$XSD}nonNegativeInteger",
+                    maxLength =>      "{$XSD}nonNegativeInteger",
+                    totalDigits =>    "{$XSD}positiveInteger",
+                    fractionDigits => "{$XSD}nonNegativeInteger");
 
 sub parse {
-    my ($pkg, $data) = @_;
-    my $self = $pkg->new();
+    my ($pkg, $data, $schema, $parser) = @_;
+    my $self = $pkg->new({attributes => {
+	schema => $schema, 
+	parser => $parser
+	}});
 
-    my $name = _attr($data, 'name');
+    my $name = $self->attributes->{parser}->namespaced_name($data, 'name');
     $self->name($name) if $name;
 
     $self->{restrictions} = {};
@@ -38,7 +42,7 @@
 sub parse_restriction {
     my ($self, $data) = @_;
 
-    my $base = _attr($data, 'base');
+    my $base = $self->attributes->{parser}->namespaced_name($data, 'base');
     _err("Found restriction without required 'base' attribute.")
       unless $base;
     $self->{base} = $base;
@@ -60,7 +64,7 @@
     my ($self) = shift;
 
     # compile a new type
-    my $base = $self->root->{type_library}->find(name => $self->{base});
+    my $base = $self->attributes->{schema}{type_library}->find(name => $self->{base});
     my $type = $base->derive();
     
     # smoke 'em if you got 'em
@@ -78,8 +82,9 @@
     }
 
     # register in the library if this is a named type
-    $self->root->{type_library}->add(name => $self->{name},
-                                     obj  => $type)
+    $self->attributes->{schema}{type_library}->add(name => $self->{name},
+                                     obj  => $type, 
+				     parser => $self->attributes->{parser})
       if $self->{name};
 
     return $type;
@@ -87,7 +92,7 @@
 
 sub check_facet_value {
   my ($self, $facet, $value, $type_name) = @_;
-  my ($ok, $msg) = $self->root->{type_library}->find(name => $type_name)->check($value);
+  my ($ok, $msg) = $self->attributes->{schema}{type_library}->find(name => $type_name)->check($value);
   _err("Facet <$facet> value $value is not a $type_name")
     unless $ok;
 }
diff -Naur orig/XML-Validator-Schema/Schema/TypeLibrary.pm XML-Validator-Schema/Schema/TypeLibrary.pm
--- orig/XML-Validator-Schema/Schema/TypeLibrary.pm	2005-10-22 06:07:15.000000000 -0700
+++ XML-Validator-Schema/Schema/TypeLibrary.pm	2006-02-01 15:20:49.000000000 -0800
@@ -36,7 +36,7 @@
     my $self = $pkg->SUPER::new(what => 'type', @_);
     
     # load builtin simple types into XSD namespace
-    $self->{stacks}{XSD()} = { %XML::Validator::Schema::SimpleType::BUILTIN };
+    $self->{stacks}{XSD()} = { map { ( $_ => [$XML::Validator::Schema::SimpleType::BUILTIN{$_}, '[ -- init -- ]'] ) } keys %XML::Validator::Schema::SimpleType::BUILTIN };
 
     return $self;
 }
diff -Naur orig/XML-Validator-Schema/Schema.pm XML-Validator-Schema/Schema.pm
--- orig/XML-Validator-Schema/Schema.pm	2005-10-22 06:05:32.000000000 -0700
+++ XML-Validator-Schema/Schema.pm	2006-02-01 15:35:58.000000000 -0800
@@ -501,6 +501,10 @@
 
 our $DEBUG = 0;
 
+use constant NODE_STACK => 0;
+use constant LOCATOR => 1;
+use constant ROOT => 2;
+
 # create a new validation filter
 sub new {
     my $pkg  = shift;
@@ -508,17 +512,87 @@
     my $self = bless $opt, $pkg;
 
     $self->{debug} = exists $self->{debug} ? $self->{debug} : $DEBUG;
+    $self->{locator} = undef;
+    $self->{document_states} = {};
+    $self->{document_stack} = [];
+
+    # start up with empty libraries
+    $self->{type_library}      = XML::Validator::Schema::TypeLibrary->new;
+    $self->{element_library}   = XML::Validator::Schema::ElementLibrary->new;
+    $self->{attribute_library} = XML::Validator::Schema::AttributeLibrary->new;
 
     # check options
-    croak("Missing required 'file' option.") unless $self->{file};
+    if ($self->{file}) {
+
+	$self->parse_schema($self->{file});
+#	while (my ($docoment, $states) = each %{$self->{document2root}}) {
+#	    $states->[ROOT]->compile();
+#	}
+
+	# buffer text for convenience
+	my $bf = XML::Filter::BufferText->new( Handler => $self );
+
+	# add line-numbers and column-numbers to errors if
+	# XML::Filter::ExceptionLocator is available
+	eval { require XML::Filter::ExceptionLocator; };
+	if ($@) {
+	    # no luck, just return the buffer-text handler
+	    return $bf;
+	} else {
+	    # create a new exception-locator and return it
+	    my $el = XML::Filter::ExceptionLocator->new( Handler => $bf );
+	    return $el;
+	}
+    } elsif ($self->{systemID}) {
+	$self->prepare_parser($self->{systemID});
+	return $self;
+    } else {
+	croak("Missing required 'file' option.");
+    }
+}
+
+sub prepare_parser {
+    my ($self, $file) = @_;
+    # create an empty element stack
+    $self->{node_stack} = [];
+
+
+
+    # initialize the schema parser
+    $self->{XSDhandler} = XML::Validator::Schema::Parser->new(schema => $self);
+
+    # add line-numbers and column-numbers to errors if
+    # XML::Filter::ExceptionLocator is available
+    eval { require XML::Filter::ExceptionLocator; };
+    unless ($@) {
+	# create a new exception-locator and set it up above the parser
+	$self->{XSDhandler} = XML::Filter::ExceptionLocator->new( Handler => $self->{XSDhandler} );
+    }
+
+    # parse the schema file
+    push (@{$self->{document_stack}}, $file);
+
+    $self->{document_states}{$file}[NODE_STACK] = $self->{node_stack};
+    # set up a fake locator in case the parser doesn't give us one.
+    $self->{oldLocator} = $self->{locator};
+    $self->{locator} = {ColumnNumber => 1, LineNumber => 1, PublicId => '', SystemId => $file, Encoding => '', XMLVersion => ''};
+}
+
+# parse an XML schema document, filling $self->{node_stack}
+sub parse_schema {
+    my $self = shift;
+    my $file = shift;
+
+    return if exists $self->{document_states}{$file}; # don't eat our tail
+    $self->{document_states}{$file} = [undef, undef, undef]; # mark pending
 
     # if caching is on, check the cache
     if ($self->{cache} and
-        exists $CACHE{$self->{file}} and 
-        $CACHE{$self->{file}}{mtime} == (stat($self->{file}))[9]) {
+        exists $CACHE{$file} and 
+        $CACHE{$file}{mtime} == (stat($file))[9]) {
 
         # load cached object
-        $self->{node_stack} = $CACHE{$self->{file}}{node_stack};
+        $self->{node_stack} = $CACHE{$file}{node_stack};
 
         # might have nodes on it leftover from failed validation,
         # truncate to root
@@ -529,62 +603,73 @@
            { callback => sub { shift->clear_memory; 1; } });
 
     } else {
-        # create an empty element stack
-        $self->{node_stack} = [];
-
-        # load the schema, filling in the element tree
-        $self->parse_schema();
-
-        # store to cache
-        if ($self->{cache}) {
-            $CACHE{$self->{file}}{mtime} = (stat($self->{file}))[9];
-            $CACHE{$self->{file}}{node_stack} = $self->{node_stack};
-        }
+	# load the schema, filling in the element tree
+	_err("Specified schema file '$file' does not exist.")
+	    unless -e $file;
+
+	$self->prepare_parser($file);
+	my $parser = XML::SAX::ParserFactory->parser(Handler => $self->{XSDhandler});
+	$parser->parse_uri($file);
+	$self->finish_parser($file);
     }
+}
 
-    # buffer text for convenience
-    my $bf = XML::Filter::BufferText->new( Handler => $self );
-
-    # add line-numbers and column-numbers to errors if
-    # XML::Filter::ExceptionLocator is available
-    eval { require XML::Filter::ExceptionLocator; };
-    if ($@) {
-        # no luck, just return the buffer-text handler
-        return $bf;
-    } else {
-        # create a new exception-locator and return it
-        my $el = XML::Filter::ExceptionLocator->new( Handler => $bf );
-        return $el;
+sub finish_parser {
+    my ($self, $file) = @_;
+    $self->{locator} = $self->{oldLocator};
+
+    # store to cache
+    if ($self->{cache}) {
+	$CACHE{$file}{mtime} = (stat($file))[9];
+	$CACHE{$file}{node_stack} = $self->{node_stack};
     }
 }
 
-# parse an XML schema document, filling $self->{node_stack}
-sub parse_schema {
-    my $self = shift;
+sub add_root {
+    my ($self, $root) = @_;
+    my $doc = pop @{$self->{document_stack}};
+    $self->{document_states}{$doc}[ROOT] = $root;
+    if (@{$self->{document_stack}}) {
+	$doc = $self->{document_stack}[-1];
+    }
+    $self->{node_stack} = $self->{document_states}{$doc}[NODE_STACK];
+    $self->{locator} = $self->{document_states}{$doc}[LOCATOR];
+}
 
-    _err("Specified schema file '$self->{file}' does not exist.")
-      unless -e $self->{file};
-    
-    # initialize the schema parser
-    my $parser = XML::Validator::Schema::Parser->new(schema => $self);
+sub set_schema_document_locator {
+    my ($self, $locator) = @_;
+    $self->{locator} = $locator;
+    my $doc = $self->{document_stack}[-1];
+    $self->{document_states}{$doc}[LOCATOR] = $locator;
+}
 
-    # add line-numbers and column-numbers to errors if
-    # XML::Filter::ExceptionLocator is available
-    eval { require XML::Filter::ExceptionLocator; };
-    unless ($@) {
-        # create a new exception-locator and set it up above the parser
-        $parser = XML::Filter::ExceptionLocator->new( Handler => $parser );
-    }
+sub set_document_locator {
+    my ($self, $locator) = @_;
+    $self->{locator} = $locator;
+}
 
-    # parse the schema file
-    $parser = XML::SAX::ParserFactory->parser(Handler => $parser);
-    $parser->parse_uri($self->{file});
+sub add_error_context {
+    my ($self, $msg) = @_;
+    my $locator = $self->{locator};
+    my @lines = split(/\n/, $msg);
+    $lines [0] .= " [Id: $locator->{SystemId}, Ln: $locator->{LineNumber}, Col: $locator->{ColumnNumber}]" if  0 && $locator;
+    return join("\n", @lines);
 }
 
 # check element start
 sub start_element {
     my ($self, $data) = @_;
-    my $name = $data->{LocalName};
+    eval {
+	$self->start_element1($data);
+    }; if ($@) {
+	$@ = $self->add_error_context($@);
+	die "$@\n";
+    }
+}
+
+sub start_element1 {
+    my ($self, $data) = @_;
+    my $name = "{$data->{NamespaceURI}}$data->{LocalName}";
     my $node_stack = $self->{node_stack};
     my $element = $node_stack->[-1];
 
@@ -592,10 +677,10 @@
       if $self->{debug};
 
     # check that this alright
-    my $daughter = $element->check_daughter($name);
+    my $daughter = $element->check_daughter($name, $self->{locator});
 
     # check attributes
-    $daughter->check_attributes($data->{Attributes});
+    $daughter->check_attributes($data->{Attributes}, $self->{locator});
     
     if ($self->{debug}) {
         foreach my $att ( keys %{ $data->{Attributes} } ) {
@@ -614,8 +699,18 @@
 # check character content
 sub characters {
     my ($self, $data) = @_;
+    eval {
+	$self->characters1($data);
+    }; if ($@) {
+	$@ = $self->add_error_context($@);
+	die "$@\n";
+    }
+}
+
+sub characters1 {
+    my ($self, $data) = @_;
     my $element = $self->{node_stack}[-1];
-    $element->check_contents($data->{Data});
+    $element->check_contents($data->{Data}, $self->{locator});
     $element->{checked_content} = 1;
 
     $self->SUPER::characters($data);
@@ -624,11 +719,21 @@
 # finish element checking
 sub end_element {
     my ($self, $data) = @_;
+    eval {
+	$self->end_element1($data);
+    }; if ($@) {
+	$@ = $self->add_error_context($@);
+	die "$@\n";
+    }
+}
+
+sub end_element1 {
+    my ($self, $data) = @_;
     my $node_stack = $self->{node_stack};
     my $element = $node_stack->[-1];
 
     # check empty content if haven't checked yet
-    $element->check_contents('')
+    $element->check_contents('', $self->{locator})
       unless $element->{checked_content};
     $element->{checked_content} = 0;
 
diff -Naur orig/XML-Validator-Schema/t/03types.t XML-Validator-Schema/t/03types.t
--- orig/XML-Validator-Schema/t/03types.t	2005-10-22 06:05:42.000000000 -0700
+++ XML-Validator-Schema/t/03types.t	2006-02-01 15:20:49.000000000 -0800
@@ -4,16 +4,17 @@
 
 use Test::More qw(no_plan);
 use XML::Validator::Schema::TypeLibrary;
+use XML::Validator::Schema::Util qw(XSD);
 my $lib = XML::Validator::Schema::TypeLibrary->new();
 
 sub supported_type {
-    return 1 if $lib->find(name => shift);
+    return 1 if $lib->find(name => '{'.XSD.'}'.shift);
     return 0;
 }
 
 our $LAST_MSG;
 sub check_type {
-    my $type = $lib->find(name => shift);
+    my $type = $lib->find(name => '{'.XSD.'}'.shift);
     return 0 unless $type;
     my ($ok, $msg) = $type->check(shift);
     $LAST_MSG = $msg;
diff -Naur orig/XML-Validator-Schema/t/04model.t XML-Validator-Schema/t/04model.t
--- orig/XML-Validator-Schema/t/04model.t	2005-10-22 06:05:43.000000000 -0700
+++ XML-Validator-Schema/t/04model.t	2006-02-01 16:02:50.000000000 -0800
@@ -4,16 +4,33 @@
 
 use Test::More qw(no_plan);
 use XML::Validator::Schema;
+use XML::Validator::Schema::Util qw(_attr);
 use XML::Validator::Schema::ElementNode;
 use XML::Validator::Schema::ModelNode;
 
+# --- Simulate a Parser ---
+my $self = bless ({}, 'test');
+# These tests don't have a targetNamespace.
+sub test::targeted_element_name {
+    my ($self, $name) = @_;
+    return "{}$name";
+}
+sub test::namespaced_name {
+    my ($self, $data, $name) = @_;
+    if (my $ret = _attr($data, $name)) {
+	return "{}$ret";
+    }
+    return undef;
+}
+
+
 # create test elements
 my $foo = XML::Validator::Schema::ElementNode->parse(
-           { Attributes => { '{}name' => { Value => 'foo' } } });
+           { Attributes => { '{}name' => { Value => 'foo' } } }, undef, $self);
 my $bar = XML::Validator::Schema::ElementNode->parse(
-           { Attributes => { '{}name' => { Value => 'bar' } } });
+           { Attributes => { '{}name' => { Value => 'bar' } } }, undef, $self);
 my $baz = XML::Validator::Schema::ElementNode->parse(
-           { Attributes => { '{}name' => { Value => 'baz' } } });
+           { Attributes => { '{}name' => { Value => 'baz' } } }, undef, $self);
 
 # foo contains a sequence of (bar, baz)
 my $sequence = XML::Validator::Schema::ModelNode->parse({ LocalName => 'sequence' });
@@ -29,19 +46,19 @@
 isa_ok($foo->{model}, 'XML::Validator::Schema::ModelNode');
 
 # check the description
-is($foo->{model}->{description}, "(bar,baz)");
+is($foo->{model}->{description}, "({}bar,{}baz)");
 
 # check a sequence of nodes against the model
-eval { $foo->{model}->check_final_model('', ['bar', 'baz']) };
+eval { $foo->{model}->check_final_model('', ['{}bar', '{}baz']) };
 is($@, "");
 
-eval { $foo->{model}->check_model('', ['bar']) };
+eval { $foo->{model}->check_model('', ['{}bar']) };
 is($@, "");
 
 eval { $foo->{model}->check_final_model('', []) };
 like($@, qr/do not match content model/);
 
-eval { $foo->{model}->check_model('', ['baz']) };
+eval { $foo->{model}->check_model('', ['{}baz']) };
 like($@, qr/does not match content model/);
 
 
@@ -61,19 +78,19 @@
 isa_ok($foo->{model}, 'XML::Validator::Schema::ModelNode');
 
 # check the description
-is($foo->{model}->{description}, "(baz|bar)");
+is($foo->{model}->{description}, "({}baz|{}bar)");
 
 # check a sequence of nodes against the model
-eval { $foo->{model}->check_final_model('', ['bar']) };
+eval { $foo->{model}->check_final_model('', ['{}bar']) };
 is($@, "");
 
-eval { $foo->{model}->check_model('', ['baz']) };
+eval { $foo->{model}->check_model('', ['{}baz']) };
 is($@, "");
 
 eval { $foo->{model}->check_final_model('', []) };
 like($@, qr/do not match content model/);
 
-eval { $foo->{model}->check_model('', ['bar', 'baz']) };
+eval { $foo->{model}->check_model('', ['{}bar', '{}baz']) };
 like($@, qr/does not match content model/);
 
 # foo contains an 'all' of (bar&baz)
@@ -92,30 +109,30 @@
 isa_ok($foo->{model}, 'XML::Validator::Schema::ModelNode');
 
 # check the description
-is($foo->{model}->{description}, "(bar&baz)");
+is($foo->{model}->{description}, "({}bar&{}baz)");
 
 # check a sequence of nodes against the model
-eval { $foo->{model}->check_final_model('', ['bar', 'baz']) };
+eval { $foo->{model}->check_final_model('', ['{}bar', '{}baz']) };
 is($@, "");
 
-eval { $foo->{model}->check_final_model('', ['baz', 'bar']) };
+eval { $foo->{model}->check_final_model('', ['{}baz', '{}bar']) };
 is($@, "");
 
 eval { $foo->{model}->check_final_model('', []) };
 like($@, qr/do not match content model/);
 
 my $bang = XML::Validator::Schema::ElementNode->parse(
-           { Attributes => { '{}name' => { Value => 'bang' } } });
+           { Attributes => { '{}name' => { Value => '{}bang' } } }, undef, $self);
 my $bop = XML::Validator::Schema::ElementNode->parse(
-           { Attributes => { '{}name' => { Value => 'bop' } } });
+           { Attributes => { '{}name' => { Value => '{}bop' } } }, undef, $self);
 
 
 # foo contains a sequence with a choice of (bar,(bang|bop),baz)
-$sequence = XML::Validator::Schema::ModelNode->parse({ LocalName => 'sequence' });
+$sequence = XML::Validator::Schema::ModelNode->parse({ LocalName => 'sequence' }, undef, $self);
 $foo->clear_daughters();
 $foo->{model} = undef;
 $foo->add_daughter($sequence);
-$choice = XML::Validator::Schema::ModelNode->parse({ LocalName => 'choice' });
+$choice = XML::Validator::Schema::ModelNode->parse({ LocalName => 'choice' }, undef, $self);
 $choice->add_daughters($bang, $bop);
 $sequence->add_daughters($bar, $choice, $baz);
 is($sequence->daughters(), 3);
@@ -127,23 +144,24 @@
 is($foo->daughters, 4);
 
 # check the description
-is($foo->{model}->{description}, "(bar,(bang|bop),baz)");
+is($foo->{model}->{description}, "({}bar,({}bang|{}bop),{}baz)");
 
 # check a sequence of nodes against the model
-eval { $foo->{model}->check_final_model('', ['bar', 'bang', 'baz']) };
+eval { $foo->{model}->check_final_model('', ['{}bar', '{}bang', '{}baz']) };
 is($@, "");
 
-eval { $foo->{model}->check_final_model('', ['bar', 'bop', 'baz']) };
+eval { $foo->{model}->check_final_model('', ['{}bar', '{}bop', '{}baz']) };
 is($@, "");
 
-eval { $foo->{model}->check_model('', ['bar']) };
+eval { $foo->{model}->check_model('', ['{}bar']) };
 is($@, "");
 
-eval { $foo->{model}->check_model('', ['bar', 'bang']) };
+eval { $foo->{model}->check_model('', ['{}bar', '{}bang']) };
 is($@, "");
 
-eval { $foo->{model}->check_final_model('', ['bar', 'bang', 'bop', 'baz']) };
+eval { $foo->{model}->check_final_model('', ['{}bar', '{}bang', '{}bop', '{}baz']) };
 like($@, qr/do not match content model/);
 
-eval { $foo->{model}->check_model('', ['baz']) };
+eval { $foo->{model}->check_model('', ['{}baz']) };
 like($@, qr/does not match content model/);
+
diff -Naur orig/XML-Validator-Schema/t/all_min0.yml XML-Validator-Schema/t/all_min0.yml
--- orig/XML-Validator-Schema/t/all_min0.yml	2005-10-22 06:05:45.000000000 -0700
+++ XML-Validator-Schema/t/all_min0.yml	2006-02-01 15:20:49.000000000 -0800
@@ -1,15 +1,15 @@
 # test the <xsd:all> works correctly with minOccurs="0" elements
 --- |
   <?xml version="1.0" encoding="UTF-8"?>
-  <schema xmlns="http://www.w3.org/2001/XMLSchema">
-    <element name="test" type="Test"/>
-    <complexType name="Test">
-      <all>
-        <element name="aString" type="string"/>
-        <element name="bString" type="string" minOccurs="0"/>
-      </all>
-    </complexType>
-  </schema>
+  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+    <xs:element name="test" type="Test"/>
+    <xs:complexType name="Test">
+      <xs:all>
+        <xs:element name="aString" type="xs:string"/>
+        <xs:element name="bString" type="xs:string" minOccurs="0"/>
+      </xs:all>
+    </xs:complexType>
+  </xs:schema>
 
 --- |
   <test>
diff -Naur orig/XML-Validator-Schema/t/all_ns.yml XML-Validator-Schema/t/all_ns.yml
--- orig/XML-Validator-Schema/t/all_ns.yml	1969-12-31 16:00:00.000000000 -0800
+++ XML-Validator-Schema/t/all_ns.yml	2006-02-01 15:20:49.000000000 -0800
@@ -0,0 +1,95 @@
+# simple all namespace test
+
+--- |
+  <?xml version="1.0" encoding="UTF-8"?>
+  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+             targetNamespace="http://t.example/"
+             elementFormDefault="qualified"
+             attributeFormDefault="qualified"
+             xmlns:foo="http://t.example/">
+    <xs:element name="foo">
+      <xs:complexType>
+        <xs:all>
+          <xs:element name="this" />
+          <xs:element name="other" minOccurs="0"/>
+          <xs:element name="that" />
+        </xs:all>
+      </xs:complexType>
+    </xs:element>
+  </xs:schema>
+
+--- |
+  <t:foo xmlns:t="http://t.example/">
+    <t:this/>
+    <t:that/>
+  </t:foo>
+--- >
+PASS
+
+--- |
+  <foo xmlns="http://t.example/">
+    <this/>
+    <that/>
+  </foo>
+--- >
+PASS
+
+--- |
+  <t:foo>
+    <t:this/>
+    <t:that/>
+  </t:foo>
+--- >
+FAIL
+
+--- |
+  <t:foo xmlns:t="http://t.example/">
+    <t:that/>
+    <t:this/>
+  </t:foo>
+--- >
+PASS
+
+--- |
+  <t:foo xmlns:t="http://t.example/">
+    <t:this/>
+    <t:that/>
+    <t:other/>
+  </t:foo>
+--- >
+PASS
+
+--- |
+  <t:foo xmlns:t="http://t.example/">
+    <t:other/>
+    <t:that/>
+    <t:this/>
+  </t:foo>
+--- >
+PASS
+
+--- |
+  <t:foo xmlns:t="http://t.example/">
+    <t:that/>
+  </t:foo>
+--- >
+FAIL
+
+--- |
+  <t:foo xmlns:t="http://t.example/">
+    <t:this/>
+  </t:foo>
+--- >
+FAIL
+
+--- |
+  <t:foo xmlns:t="http://t.example/">
+    <t:that/>
+    <t:this/>
+    <t:that/>
+  </t:foo>
+--- >
+FAIL
+
+
+
diff -Naur orig/XML-Validator-Schema/t/all.yml XML-Validator-Schema/t/all.yml
--- orig/XML-Validator-Schema/t/all.yml	2005-10-22 06:05:45.000000000 -0700
+++ XML-Validator-Schema/t/all.yml	2006-02-01 15:20:49.000000000 -0800
@@ -2,17 +2,17 @@
 
 --- |
   <?xml version="1.0" encoding="UTF-8"?>
-  <schema xmlns="http://www.w3.org/2001/XMLSchema">
-    <element name="foo">
-      <complexType>
-        <all>
-          <element name="this" />
-          <element name="other" minOccurs="0"/>
-          <element name="that" />
-        </all>
-      </complexType>
-    </element>
-  </schema>
+  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+    <xs:element name="foo">
+      <xs:complexType>
+        <xs:all>
+          <xs:element name="this" />
+          <xs:element name="other" minOccurs="0"/>
+          <xs:element name="that" />
+        </xs:all>
+      </xs:complexType>
+    </xs:element>
+  </xs:schema>
 
 --- |
   <foo>
diff -Naur orig/XML-Validator-Schema/t/attribute_types.yml XML-Validator-Schema/t/attribute_types.yml
--- orig/XML-Validator-Schema/t/attribute_types.yml	2005-10-22 06:05:47.000000000 -0700
+++ XML-Validator-Schema/t/attribute_types.yml	2006-02-01 15:20:49.000000000 -0800
@@ -2,27 +2,27 @@
 
 --- |
   <?xml version="1.0" encoding="UTF-8"?>
-  <schema xmlns="http://www.w3.org/2001/XMLSchema">
-    <element name="foo">
-      <complexType>
-        <attribute name="no_type" use="optional" />
-        <attribute name="int" type="int" use="optional" />
-        <attribute name="integer" type="integer" use="optional" />
-        <attribute name="name" type="NMTOKEN" use="optional"  />
-        <attribute name="string" type="string" use="optional" />
-        <attribute name="bool" type="boolean" use="optional" />
-        <attribute name="date" type="dateTime" use="optional" />
-        <attribute name="foo_or_bar" use="optional">
-          <simpleType>
-            <restriction base="xsd:string">
-              <enumeration value="foo"/>
-              <enumeration value="bar"/>
-            </restriction>
-          </simpleType>
-        </attribute>
-      </complexType>
-    </element>
-  </schema>
+  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+    <xs:element name="foo">
+      <xs:complexType>
+        <xs:attribute name="no_type" use="optional" />
+        <xs:attribute name="int" type="xs:int" use="optional" />
+        <xs:attribute name="integer" type="xs:integer" use="optional" />
+        <xs:attribute name="name" type="xs:NMTOKEN" use="optional"  />
+        <xs:attribute name="string" type="xs:string" use="optional" />
+        <xs:attribute name="bool" type="xs:boolean" use="optional" />
+        <xs:attribute name="date" type="xs:dateTime" use="optional" />
+        <xs:attribute name="foo_or_bar" use="optional">
+          <xs:simpleType>
+            <xs:restriction base="xs:string">
+              <xs:enumeration value="foo"/>
+              <xs:enumeration value="bar"/>
+            </xs:restriction>
+          </xs:simpleType>
+        </xs:attribute>
+      </xs:complexType>
+    </xs:element>
+  </xs:schema>
 
 --- |
   <foo no_type="foo"/>
diff -Naur orig/XML-Validator-Schema/t/attribute.yml XML-Validator-Schema/t/attribute.yml
--- orig/XML-Validator-Schema/t/attribute.yml	2005-10-22 06:05:46.000000000 -0700
+++ XML-Validator-Schema/t/attribute.yml	2006-02-01 15:20:49.000000000 -0800
@@ -2,14 +2,14 @@
 
 --- |
   <?xml version="1.0" encoding="UTF-8"?>
-  <schema xmlns="http://www.w3.org/2001/XMLSchema">
-    <element name="foo">
-      <complexType>
-        <attribute name="bar" />
-        <attribute name="baz" use="required" />
-      </complexType>
-    </element>
-  </schema>
+  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+    <xs:element name="foo">
+      <xs:complexType>
+        <xs:attribute name="bar" />
+        <xs:attribute name="baz" use="required" />
+      </xs:complexType>
+    </xs:element>
+  </xs:schema>
 
 --- |
   <foo baz="1"/>
diff -Naur orig/XML-Validator-Schema/t/bad_all.yml XML-Validator-Schema/t/bad_all.yml
--- orig/XML-Validator-Schema/t/bad_all.yml	2005-10-22 06:05:49.000000000 -0700
+++ XML-Validator-Schema/t/bad_all.yml	2006-02-01 15:20:49.000000000 -0800
@@ -2,17 +2,17 @@
 
 --- |
   <?xml version="1.0" encoding="UTF-8"?>
-  <schema xmlns="http://www.w3.org/2001/XMLSchema">
-    <element name="foo">
-      <complexType>
-        <all>
-          <element name="this" />
-          <element name="other" maxOccurs="unbounded"/>
-          <element name="that" />
-        </all>
-      </complexType>
-    </element>
-  </schema>
+  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+    <xs:element name="foo">
+      <xs:complexType>
+        <xs:all>
+          <xs:element name="this" />
+          <xs:element name="other" maxOccurs="unbounded"/>
+          <xs:element name="that" />
+        </xs:all>
+      </xs:complexType>
+    </xs:element>
+  </xs:schema>
 
 --- |
   <foo>
diff -Naur orig/XML-Validator-Schema/t/bad_attribute_type.yml XML-Validator-Schema/t/bad_attribute_type.yml
--- orig/XML-Validator-Schema/t/bad_attribute_type.yml	2005-10-22 06:05:50.000000000 -0700
+++ XML-Validator-Schema/t/bad_attribute_type.yml	2006-02-01 15:20:49.000000000 -0800
@@ -2,13 +2,13 @@
 
 --- |
   <?xml version="1.0" encoding="UTF-8"?>
-  <schema xmlns="http://www.w3.org/2001/XMLSchema">
-    <element name="foo">
-      <complexType>
-        <attribute name="typed" type="foobar" />
-      </complexType>
-    </element>
-  </schema>
+  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+    <xs:element name="foo">
+      <xs:complexType>
+        <xs:attribute name="typed" type="foobar" />
+      </xs:complexType>
+    </xs:element>
+  </xs:schema>
 
 --- |
   <foo typed="foo"/>
diff -Naur orig/XML-Validator-Schema/t/bad.xsd XML-Validator-Schema/t/bad.xsd
--- orig/XML-Validator-Schema/t/bad.xsd	2005-10-22 06:05:49.000000000 -0700
+++ XML-Validator-Schema/t/bad.xsd	2006-02-01 15:20:49.000000000 -0800
@@ -1,16 +1,16 @@
 <?xml version="1.0" encoding="UTF-8"?>
-  <schema xmlns="http://www.w3.org/2001/XMLSchema">
-    <element name="foo">
-      <zomplexType>
-        <sequence>
-          <element name="no_type" minOccurs="0" />
-          <element name="int" type="int" minOccurs="0" />
-          <element name="integer" type="integer" minOccurs="0" />
-          <element name="name" type="NMTOKEN" minOccurs="0"  />
-          <element name="string" type="string" minOccurs="0" />
-          <element name="bool" type="boolean" minOccurs="0" />
-          <element name="date" type="dateTime" minOccurs="0" />
-        </sequence>
-      </complexType>
-    </element>
-  </schema>
+  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+    <xs:element name="foo">
+      <xs:zomplexType>
+        <xs:sequence>
+          <xs:element name="no_type" minOccurs="0" />
+          <xs:element name="int" type="int" minOccurs="0" />
+          <xs:element name="integer" type="integer" minOccurs="0" />
+          <xs:element name="name" type="NMTOKEN" minOccurs="0"  />
+          <xs:element name="string" type="string" minOccurs="0" />
+          <xs:element name="bool" type="boolean" minOccurs="0" />
+          <xs:element name="date" type="dateTime" minOccurs="0" />
+        </xs:sequence>
+      </xs:complexType>
+    </xs:element>
+  </xs:schema>
diff -Naur orig/XML-Validator-Schema/t/choice.yml XML-Validator-Schema/t/choice.yml
--- orig/XML-Validator-Schema/t/choice.yml	2005-10-22 06:06:00.000000000 -0700
+++ XML-Validator-Schema/t/choice.yml	2006-02-01 15:20:49.000000000 -0800
@@ -2,17 +2,17 @@
 
 --- |
   <?xml version="1.0" encoding="UTF-8"?>
-  <schema xmlns="http://www.w3.org/2001/XMLSchema">
-    <element name="foo">
-      <complexType>
-        <choice>
-          <element name="this" />
-          <element name="that" />
-          <element name="other"/>
-        </choice>
-      </complexType>
-    </element>
-  </schema>
+  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+    <xs:element name="foo">
+      <xs:complexType>
+        <xs:choice>
+          <xs:element name="this" />
+          <xs:element name="that" />
+          <xs:element name="other"/>
+        </xs:choice>
+      </xs:complexType>
+    </xs:element>
+  </xs:schema>
 
 --- |
   <foo>
@@ -41,7 +41,7 @@
     <that/>
   </foo>
 --- >
-FAIL /'that' does not match/
+FAIL /'{}that' does not match/
 
 --- |
   <foo>
diff -Naur orig/XML-Validator-Schema/t/content_message.yml XML-Validator-Schema/t/content_message.yml
--- orig/XML-Validator-Schema/t/content_message.yml	2005-10-22 06:06:04.000000000 -0700
+++ XML-Validator-Schema/t/content_message.yml	2006-02-01 15:20:49.000000000 -0800
@@ -1,6 +1,6 @@
 # test the error message for content-model failures
 --- |
-  <xs:schema xmlns:xs="mydoc">
+  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
     <xs:element name="A">
       <xs:complexType>
         <xs:sequence>
@@ -19,4 +19,4 @@
 --- |
   <A><C/><B/><C/></A>
 --- >
-FAIL /Inside element 'A'/
+FAIL /Inside element '{}A'/
diff -Naur orig/XML-Validator-Schema/t/element_type.yml XML-Validator-Schema/t/element_type.yml
--- orig/XML-Validator-Schema/t/element_type.yml	2005-10-22 06:06:07.000000000 -0700
+++ XML-Validator-Schema/t/element_type.yml	2006-02-01 15:20:49.000000000 -0800
@@ -2,21 +2,21 @@
 
 --- |
   <?xml version="1.0" encoding="UTF-8"?>
-  <schema xmlns="http://www.w3.org/2001/XMLSchema">
-    <element name="foo">
-      <complexType>
-        <sequence>
-          <element name="no_type" minOccurs="0" />
-          <element name="int" type="int" minOccurs="0" />
-          <element name="integer" type="integer" minOccurs="0" />
-          <element name="name" type="NMTOKEN" minOccurs="0"  />
-          <element name="string" type="string" minOccurs="0" />
-          <element name="bool" type="boolean" minOccurs="0" />
-          <element name="date" type="dateTime" minOccurs="0" />
-        </sequence>
-      </complexType>
-    </element>
-  </schema>
+  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+    <xs:element name="foo">
+      <xs:complexType>
+        <xs:sequence>
+          <xs:element name="no_type" minOccurs="0" />
+          <xs:element name="int" type="xs:int" minOccurs="0" />
+          <xs:element name="integer" type="xs:integer" minOccurs="0" />
+          <xs:element name="name" type="xs:NMTOKEN" minOccurs="0"  />
+          <xs:element name="string" type="xs:string" minOccurs="0" />
+          <xs:element name="bool" type="xs:boolean" minOccurs="0" />
+          <xs:element name="date" type="xs:dateTime" minOccurs="0" />
+        </xs:sequence>
+      </xs:complexType>
+    </xs:element>
+  </xs:schema>
 
 --- |
   <foo>
diff -Naur orig/XML-Validator-Schema/t/foo.yml XML-Validator-Schema/t/foo.yml
--- orig/XML-Validator-Schema/t/foo.yml	2005-10-22 06:06:10.000000000 -0700
+++ XML-Validator-Schema/t/foo.yml	2006-02-01 15:20:49.000000000 -0800
@@ -3,9 +3,9 @@
 
 --- |
   <?xml version="1.0" encoding="UTF-8"?>
-  <schema xmlns="http://www.w3.org/2001/XMLSchema">
-    <element name="foo" />
-  </schema>
+  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+    <xs:element name="foo" />
+  </xs:schema>
 
 --- |
   <?xml version="1.0" encoding="UTF-8"?>
@@ -17,11 +17,11 @@
   <?xml version="1.0" encoding="UTF-8"?>
   <fooz />
 --- >
-FAIL /unexpected <fooz>/
+FAIL /unexpected <{}fooz>/
 
 --- |
   <fooz />
 --- >
-FAIL /unexpected <fooz>/
+FAIL /unexpected <{}fooz>/
 
 
diff -Naur orig/XML-Validator-Schema/t/global_type.yml XML-Validator-Schema/t/global_type.yml
--- orig/XML-Validator-Schema/t/global_type.yml	2005-10-22 06:06:11.000000000 -0700
+++ XML-Validator-Schema/t/global_type.yml	2006-02-01 15:20:49.000000000 -0800
@@ -26,7 +26,7 @@
     <bif/>
   </foo>
 --- >
-FAIL /unexpected <bif>/
+FAIL /unexpected <{}bif>/
 
 --- |
   <?xml version="1.0" encoding="UTF-8"?>
diff -Naur orig/XML-Validator-Schema/t/import_different.yml XML-Validator-Schema/t/import_different.yml
--- orig/XML-Validator-Schema/t/import_different.yml	1969-12-31 16:00:00.000000000 -0800
+++ XML-Validator-Schema/t/import_different.yml	2006-02-01 15:20:49.000000000 -0800
@@ -0,0 +1,42 @@
+# import into the same namespace
+
+--- |
+  <?xml version="1.0" encoding="UTF-8"?>
+  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+             targetNamespace="http://t2.example/"
+             elementFormDefault="qualified"
+             attributeFormDefault="qualified"
+             xmlns:foo="http://t.example/">
+    <xs:import namespace="http://t.example/" schemaLocation="/usr/local/src/XML-Validator-Schema/t/test_ns.xsd"/>
+    <xs:element name="root">
+      <xs:complexType>
+        <xs:sequence>
+          <xs:element ref="foo:foo" />
+        </xs:sequence>
+      </xs:complexType>
+    </xs:element>
+  </xs:schema>
+
+
+--- |
+  <t2:root xmlns:t="http://t.example/" xmlns:t2="http://t2.example/">
+    <t:foo>
+      <t:no_type/>
+      <t:int>1</t:int>
+    </t:foo>
+  </t2:root>
+--- >
+PASS
+
+--- |
+  <t:root xmlns:t="http://t.example/">
+    <t:foo>
+      <t:no_type/>
+      <t:int>1</t:int>
+    </t:foo>
+  </t:root>
+--- >
+FAIL /Found unexpected <{http:\/\/t.example\/}root> inside/
+
+
+
diff -Naur orig/XML-Validator-Schema/t/include_same.yml XML-Validator-Schema/t/include_same.yml
--- orig/XML-Validator-Schema/t/include_same.yml	1969-12-31 16:00:00.000000000 -0800
+++ XML-Validator-Schema/t/include_same.yml	2006-02-02 12:39:39.000000000 -0800
@@ -0,0 +1,39 @@
+# import into the same namespace
+
+--- |
+  <?xml version="1.0" encoding="UTF-8"?>
+  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+             targetNamespace="http://t.example/"
+             elementFormDefault="qualified"
+             attributeFormDefault="qualified"
+             xmlns:t="http://t.example/">
+    <xs:include schemaLocation="/usr/local/src/XML-Validator-Schema/t/test_ns.xsd"/>
+    <xs:element name="root">
+      <xs:complexType>
+        <xs:sequence>
+          <xs:element ref="t:foo" />
+        </xs:sequence>
+      </xs:complexType>
+    </xs:element>
+  </xs:schema>
+
+--- |
+  <t:root xmlns:t="http://t.example/">
+    <t:foo>
+      <t:no_type/>
+      <t:int>1</t:int>
+    </t:foo>
+  </t:root>
+--- >
+PASS
+
+--- |
+  <t2:root xmlns:t="http://t.example/" xmlns:t2="http://t2.example/">
+    <t:foo>
+      <t:no_type/>
+      <t:int>1</t:int>
+    </t:foo>
+  </t2:root>
+--- >
+FAIL /Found unexpected <{http:\/\/t2.example\/}root> inside/
+
diff -Naur orig/XML-Validator-Schema/t/min_exclusive.yml XML-Validator-Schema/t/min_exclusive.yml
--- orig/XML-Validator-Schema/t/min_exclusive.yml	2005-10-22 06:06:14.000000000 -0700
+++ XML-Validator-Schema/t/min_exclusive.yml	2006-02-01 15:20:49.000000000 -0800
@@ -1,13 +1,13 @@
 --- |
   <?xml version="1.0" encoding="UTF-8"?>
-  <schema xmlns="http://www.w3.org/2001/XMLSchema">
-    <element name="foo" type="sometype"/>
-    <simpleType name="sometype">
-       <restriction base="decimal">
-          <minExclusive value="-50"/>
-       </restriction>
-    </simpleType>
-  </schema>
+  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+    <xs:element name="foo" type="sometype"/>
+    <xs:simpleType name="sometype">
+       <xs:restriction base="xs:decimal">
+          <xs:minExclusive value="-50"/>
+       </xs:restriction>
+    </xs:simpleType>
+  </xs:schema>
 
 --- |
   <foo>-49</foo>
diff -Naur orig/XML-Validator-Schema/t/multi_level.yml XML-Validator-Schema/t/multi_level.yml
--- orig/XML-Validator-Schema/t/multi_level.yml	2005-10-22 06:06:15.000000000 -0700
+++ XML-Validator-Schema/t/multi_level.yml	2006-02-01 15:20:49.000000000 -0800
@@ -2,23 +2,23 @@
 
 --- |
   <?xml version="1.0" encoding="UTF-8"?>
-  <schema xmlns="http://www.w3.org/2001/XMLSchema">
-    <element name="foo">
-      <complexType>
-        <sequence>
-          <element name="bar" maxOccurs="unbounded">
-            <complexType>
-              <sequence>
-                 <element name="leaf1" minOccurs="0" maxOccurs="unbounded" />
-                 <element name="leaf2" minOccurs="0" maxOccurs="unbounded" />
-              </sequence>
-            </complexType>
-          </element>
-          <element name="baz" minOccurs="0" />
-        </sequence>
-      </complexType>
-    </element>
-  </schema>
+  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+    <xs:element name="foo">
+      <xs:complexType>
+        <xs:sequence>
+          <xs:element name="bar" maxOccurs="unbounded">
+            <xs:complexType>
+              <xs:sequence>
+                 <xs:element name="leaf1" minOccurs="0" maxOccurs="unbounded" />
+                 <xs:element name="leaf2" minOccurs="0" maxOccurs="unbounded" />
+              </xs:sequence>
+            </xs:complexType>
+          </xs:element>
+          <xs:element name="baz" minOccurs="0" />
+        </xs:sequence>
+      </xs:complexType>
+    </xs:element>
+  </xs:schema>
 
 --- |
   <?xml version="1.0" encoding="UTF-8"?>
diff -Naur orig/XML-Validator-Schema/t/multiroot.yml XML-Validator-Schema/t/multiroot.yml
--- orig/XML-Validator-Schema/t/multiroot.yml	2005-10-22 06:06:15.000000000 -0700
+++ XML-Validator-Schema/t/multiroot.yml	2006-02-01 15:20:49.000000000 -0800
@@ -2,10 +2,10 @@
 
 --- |
   <?xml version="1.0" encoding="UTF-8"?>
-  <schema xmlns="http://www.w3.org/2001/XMLSchema">
-    <element name="foo" />
-    <element name="bar" />
-  </schema>
+  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+    <xs:element name="foo" />
+    <xs:element name="bar" />
+  </xs:schema>
 
 --- |
   <?xml version="1.0" encoding="UTF-8"?>
@@ -23,11 +23,11 @@
   <?xml version="1.0" encoding="UTF-8"?>
   <fooz />
 --- >
-FAIL /unexpected <fooz>/
+FAIL /unexpected <{}fooz>/
 
 --- |
   <fooz />
 --- >
-FAIL /unexpected <fooz>/
+FAIL /unexpected <{}fooz>/
 
 
diff -Naur orig/XML-Validator-Schema/t/plankton_orig.xsd XML-Validator-Schema/t/plankton_orig.xsd
--- orig/XML-Validator-Schema/t/plankton_orig.xsd	1969-12-31 16:00:00.000000000 -0800
+++ XML-Validator-Schema/t/plankton_orig.xsd	2006-02-01 16:58:40.000000000 -0800
@@ -0,0 +1,100 @@
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
+<xsd:element name="invoiceNumber" type="xsd:string">
+</xsd:element>
+
+<xsd:element name="originator">
+ <xsd:complexType>
+  <xsd:sequence>
+   <xsd:element ref="companyName"/>
+   <xsd:element ref="companyContact"/>
+   <xsd:element ref="companyIdentifier"/>
+  </xsd:sequence>
+ </xsd:complexType>
+</xsd:element>
+
+<xsd:element name="companyName" type="xsd:string">
+</xsd:element>
+
+<xsd:element name="companyContact" type="xsd:string">
+</xsd:element>
+
+<xsd:element name="companyIdentifier" type="xsd:string">
+</xsd:element>
+
+<xsd:element name="receiver">
+ <xsd:complexType>
+  <xsd:sequence>
+   <xsd:element ref="companyName"/>
+   <xsd:element ref="companyContact"/>
+   <xsd:element ref="companyIdentifier"/>
+  </xsd:sequence>
+ </xsd:complexType>
+</xsd:element>
+
+<xsd:element name="itemDescription" type="xsd:string">
+</xsd:element>
+
+<xsd:element name="itemCount" type="xsd:string">
+</xsd:element>
+
+<xsd:element name="itemUnit" type="xsd:string">
+</xsd:element>
+
+<xsd:element name="itemPrice">
+ <xsd:complexType>
+ <xsd:simpleContent>
+ <xsd:extension base="xsd:string">
+  <xsd:attribute name="currency" 
+   type="xsd:string" use="required"/>
+  </xsd:extension>
+  </xsd:simpleContent>
+ </xsd:complexType>
+</xsd:element>
+
+<xsd:element name="itemTotal">
+ <xsd:complexType>
+ <xsd:simpleContent>
+ <xsd:extension base="xsd:string">
+  <xsd:attribute name="currency" 
+   type="xsd:string" use="required"/>
+  </xsd:extension>
+  </xsd:simpleContent>
+ </xsd:complexType>
+</xsd:element>
+
+<xsd:element name="lineItem">
+ <xsd:complexType>
+  <xsd:sequence>
+   <xsd:element ref="itemDescription"/>
+   <xsd:element ref="itemCount"/>
+   <xsd:element ref="itemUnit"/>
+   <xsd:element ref="itemPrice"/>
+   <xsd:element ref="itemTotal"/>
+  </xsd:sequence>
+ </xsd:complexType>
+</xsd:element>
+
+<xsd:element name="lineItems">
+ <xsd:complexType>
+  <xsd:sequence maxOccurs="unbounded">
+   <xsd:element ref="lineItem" />
+  </xsd:sequence>
+ </xsd:complexType>
+</xsd:element>
+
+<xsd:element name="total" type="xsd:string">
+</xsd:element>
+
+<xsd:element name="invoice">
+ <xsd:complexType>
+  <xsd:sequence>
+   <xsd:element ref="invoiceNumber"/>
+   <xsd:element ref="originator"/>
+   <xsd:element ref="receiver"/>
+   <xsd:element ref="lineItems"/>
+   <xsd:element ref="total"/>
+  </xsd:sequence>
+ </xsd:complexType>
+</xsd:element>
+</xsd:schema>
diff -Naur orig/XML-Validator-Schema/t/plankton.xsd XML-Validator-Schema/t/plankton.xsd
--- orig/XML-Validator-Schema/t/plankton.xsd	1969-12-31 16:00:00.000000000 -0800
+++ XML-Validator-Schema/t/plankton.xsd	2006-02-01 17:02:34.000000000 -0800
@@ -0,0 +1,100 @@
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
+<xsd:element name="invoiceNumber" type="xsd:string">
+</xsd:element>
+
+<xsd:element name="originator">
+ <xsd:complexType>
+  <xsd:sequence>
+   <xsd:element ref="companyName"/>
+   <xsd:element ref="companyContact"/>
+   <xsd:element ref="companyIdentifier"/>
+  </xsd:sequence>
+ </xsd:complexType>
+</xsd:element>
+
+<xsd:element name="companyName" type="xsd:string">
+</xsd:element>
+
+<xsd:element name="companyContact" type="xsd:string">
+</xsd:element>
+
+<xsd:element name="companyIdentifier" type="xsd:string">
+</xsd:element>
+
+<xsd:element name="receiver">
+ <xsd:complexType>
+  <xsd:sequence>
+   <xsd:element ref="companyName"/>
+   <xsd:element ref="companyContact"/>
+   <xsd:element ref="companyIdentifier"/>
+  </xsd:sequence>
+ </xsd:complexType>
+</xsd:element>
+
+<xsd:element name="itemDescription" type="xsd:string">
+</xsd:element>
+
+<xsd:element name="itemCount" type="xsd:string">
+</xsd:element>
+
+<xsd:element name="itemUnit" type="xsd:string">
+</xsd:element>
+
+<xsd:element name="itemPrice">
+ <xsd:complexType>
+ <xsd:simpleContent>
+ <xsd:extension base="xsd:string">
+  <xsd:attribute name="currency" 
+   type="xsd:string" use="required"/>
+  </xsd:extension>
+  </xsd:simpleContent>
+ </xsd:complexType>
+</xsd:element>
+
+<xsd:element name="itemTotal">
+ <xsd:complexType>
+ <xsd:simpleContent>
+ <xsd:extension base="xsd:string">
+  <xsd:attribute name="currency" 
+   type="xsd:string" use="required"/>
+  </xsd:extension>
+  </xsd:simpleContent>
+ </xsd:complexType>
+</xsd:element>
+
+<xsd:element name="lineItem">
+ <xsd:complexType>
+  <xsd:sequence>
+   <xsd:element ref="itemDescription"/>
+   <xsd:element ref="itemCount"/>
+   <xsd:element ref="itemUnit"/>
+   <xsd:element ref="itemPrice"/>
+   <xsd:element ref="itemTotal"/>
+  </xsd:sequence>
+ </xsd:complexType>
+</xsd:element>
+
+<xsd:element name="lineItems">
+ <xsd:complexType>
+  <xsd:sequence>
+   <xsd:element ref="lineItem" maxOccurs="unbounded"/>
+  </xsd:sequence>
+ </xsd:complexType>
+</xsd:element>
+
+<xsd:element name="total" type="xsd:string">
+</xsd:element>
+
+<xsd:element name="invoice">
+ <xsd:complexType>
+  <xsd:sequence>
+   <xsd:element ref="invoiceNumber"/>
+   <xsd:element ref="originator"/>
+   <xsd:element ref="receiver"/>
+   <xsd:element ref="lineItems"/>
+   <xsd:element ref="total"/>
+  </xsd:sequence>
+ </xsd:complexType>
+</xsd:element>
+</xsd:schema>
diff -Naur orig/XML-Validator-Schema/t/qualified.yml XML-Validator-Schema/t/qualified.yml
--- orig/XML-Validator-Schema/t/qualified.yml	2005-10-22 06:06:19.000000000 -0700
+++ XML-Validator-Schema/t/qualified.yml	2006-02-01 15:20:49.000000000 -0800
@@ -9,4 +9,4 @@
 --- |
   <foo />
 --- >
-FAIL /not.*?supported/
+PASS
diff -Naur orig/XML-Validator-Schema/t/repeated_groups.yml XML-Validator-Schema/t/repeated_groups.yml
--- orig/XML-Validator-Schema/t/repeated_groups.yml	2005-10-22 06:06:20.000000000 -0700
+++ XML-Validator-Schema/t/repeated_groups.yml	2006-02-01 15:20:50.000000000 -0800
@@ -2,43 +2,43 @@
 
 --- |
   <?xml version="1.0" encoding="UTF-8"?>
-  <schema xmlns="http://www.w3.org/2001/XMLSchema">
-   <element name="foo">
-      <complexType>
-        <sequence maxOccurs="unbounded">
-          <element name="one_or_more-1" minOccurs="1" maxOccurs="unbounded"/>
-          <element name="zero_or_one-2" minOccurs="0" maxOccurs="1"/>
-          <element name="one_or_two-3" minOccurs="1" maxOccurs="2"/>
-        </sequence>
-      </complexType>
-    </element>
-   <element name="bar">
-      <complexType>
-        <choice maxOccurs="3">
-          <element name="one"/>
-          <element name="two"/>
-          <element name="three"/>
-        </choice>
-      </complexType>
-    </element>
-   <element name="baz">
-      <complexType>
-        <all minOccurs="0">
-          <element name="one"/>
-          <element name="two"/>
-          <element name="three"/>
-        </all>
-      </complexType>
-    </element>
-   <element name="comp">
-      <complexType>
-        <choice maxOccurs="unbounded">
-           <element ref="foo"/>
-           <element ref="bar"/>
-        </choice>
-      </complexType>
-   </element>
-  </schema>
+  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+   <xs:element name="foo">
+      <xs:complexType>
+        <xs:sequence maxOccurs="unbounded">
+          <xs:element name="one_or_more-1" minOccurs="1" maxOccurs="unbounded"/>
+          <xs:element name="zero_or_one-2" minOccurs="0" maxOccurs="1"/>
+          <xs:element name="one_or_two-3" minOccurs="1" maxOccurs="2"/>
+        </xs:sequence>
+      </xs:complexType>
+    </xs:element>
+   <xs:element name="bar">
+      <xs:complexType>
+        <xs:choice maxOccurs="3">
+          <xs:element name="one"/>
+          <xs:element name="two"/>
+          <xs:element name="three"/>
+        </xs:choice>
+      </xs:complexType>
+    </xs:element>
+   <xs:element name="baz">
+      <xs:complexType>
+        <xs:all minOccurs="0">
+          <xs:element name="one"/>
+          <xs:element name="two"/>
+          <xs:element name="three"/>
+        </xs:all>
+      </xs:complexType>
+    </xs:element>
+   <xs:element name="comp">
+      <xs:complexType>
+        <xs:choice maxOccurs="unbounded">
+           <xs:element ref="foo"/>
+           <xs:element ref="bar"/>
+        </xs:choice>
+      </xs:complexType>
+   </xs:element>
+  </xs:schema>
 
 --- |
  <baz>
@@ -164,7 +164,7 @@
   <one_or_two-3 />
  </foo>
 --- >
-FAIL /'zero_or_one-2' does not match/
+FAIL /'{}zero_or_one-2' does not match/
 
 --- |
  <comp>
diff -Naur orig/XML-Validator-Schema/t/sequence_with_choice.yml XML-Validator-Schema/t/sequence_with_choice.yml
--- orig/XML-Validator-Schema/t/sequence_with_choice.yml	2005-10-22 06:06:25.000000000 -0700
+++ XML-Validator-Schema/t/sequence_with_choice.yml	2006-02-01 15:20:50.000000000 -0800
@@ -1,22 +1,22 @@
 # test a sequence containing a choice
 --- |
- <schema xmlns="http://www.w3.org/2001/XMLSchema">
-   <element name="container">
-     <complexType>
-       <sequence>
-         <choice>
-           <element name="head_one"/>
-           <element name="head_two"/>
-           <sequence>
-              <element name="multi_head" minOccurs="1" maxOccurs="unbounded"/>
-           </sequence>
-         </choice>
-         <element name="middle"/>
-         <element name="tail"/>
-       </sequence>
-     </complexType>
-   </element>
- </schema>
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+   <xs:element name="container">
+     <xs:complexType>
+       <xs:sequence>
+         <xs:choice>
+           <xs:element name="head_one"/>
+           <xs:element name="head_two"/>
+           <xs:sequence>
+              <xs:element name="multi_head" minOccurs="1" maxOccurs="unbounded"/>
+           </xs:sequence>
+         </xs:choice>
+         <xs:element name="middle"/>
+         <xs:element name="tail"/>
+       </xs:sequence>
+     </xs:complexType>
+   </xs:element>
+ </xs:schema>
 
 --- |
  <container>
@@ -53,7 +53,7 @@
    <tail/>
  </container>
 --- >
-FAIL /'middle' does not match content model '\(\(head_one\|head_two\|\(multi_head\+\)\),middle,tail\)'/
+FAIL /'{}middle' does not match content model '\(\({}head_one\|{}head_two\|\({}multi_head\+\)\),{}middle,{}tail\)'/
 
 --- |
  <container>
diff -Naur orig/XML-Validator-Schema/t/sequence.yml XML-Validator-Schema/t/sequence.yml
--- orig/XML-Validator-Schema/t/sequence.yml	2005-10-22 06:06:23.000000000 -0700
+++ XML-Validator-Schema/t/sequence.yml	2006-02-01 15:20:50.000000000 -0800
@@ -2,18 +2,18 @@
 
 --- |
   <?xml version="1.0" encoding="UTF-8"?>
-  <schema xmlns="http://www.w3.org/2001/XMLSchema">
-    <element name="foo">
-      <complexType>
-        <sequence>
-          <element name="one_or_more-1" minOccurs="1" maxOccurs="unbounded"/>
-          <element name="zero_or_one-2" minOccurs="0" maxOccurs="1"/>
-          <element name="one_or_two-3" minOccurs="1" maxOccurs="2"/>
-
-        </sequence>
-      </complexType>
-    </element>
-  </schema>
+  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+    <xs:element name="foo">
+      <xs:complexType>
+        <xs:sequence>
+          <xs:element name="one_or_more-1" minOccurs="1" maxOccurs="unbounded"/>
+          <xs:element name="zero_or_one-2" minOccurs="0" maxOccurs="1"/>
+          <xs:element name="one_or_two-3" minOccurs="1" maxOccurs="2"/>
+
+        </xs:sequence>
+      </xs:complexType>
+    </xs:element>
+  </xs:schema>
 
 --- |
  <foo>
@@ -56,7 +56,7 @@
   <one_or_two-3 />
  </foo>
 --- >
-FAIL /'zero_or_one-2' does not match/
+FAIL /'{}zero_or_one-2' does not match/
 
 
 
diff -Naur orig/XML-Validator-Schema/t/simple_content.yml XML-Validator-Schema/t/simple_content.yml
--- orig/XML-Validator-Schema/t/simple_content.yml	2005-10-22 06:06:27.000000000 -0700
+++ XML-Validator-Schema/t/simple_content.yml	2006-02-01 15:20:50.000000000 -0800
@@ -2,24 +2,24 @@
 
 --- |
   <?xml version="1.0" encoding="UTF-8"?>
-  <schema xmlns="http://www.w3.org/2001/XMLSchema">
-    <element name="foo">
-      <complexType>
-        <sequence>
-          <element name="integer" maxOccurs="unbounded">
-             <complexType>
-               <simpleContent>
-                  <extension base="integer">
-                     <attribute name="color" type="string" use="required"/>
-                     <attribute name="flavor" type="string" use="optional"/>
-                  </extension>
-               </simpleContent>
-             </complexType>
-          </element>
-        </sequence>
-      </complexType>
-    </element>
-  </schema>
+  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+    <xs:element name="foo">
+      <xs:complexType>
+        <xs:sequence>
+          <xs:element name="integer" maxOccurs="unbounded">
+             <xs:complexType>
+               <xs:simpleContent>
+                  <xs:extension base="xs:integer">
+                     <xs:attribute name="color" type="xs:string" use="required"/>
+                     <xs:attribute name="flavor" type="xs:string" use="optional"/>
+                  </xs:extension>
+               </xs:simpleContent>
+             </xs:complexType>
+          </xs:element>
+        </xs:sequence>
+      </xs:complexType>
+    </xs:element>
+  </xs:schema>
 
 --- |
   <foo>
diff -Naur orig/XML-Validator-Schema/t/test_ns.xsd XML-Validator-Schema/t/test_ns.xsd
--- orig/XML-Validator-Schema/t/test_ns.xsd	1969-12-31 16:00:00.000000000 -0800
+++ XML-Validator-Schema/t/test_ns.xsd	2006-02-01 15:20:50.000000000 -0800
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+             targetNamespace="http://t.example/"
+             elementFormDefault="qualified"
+             attributeFormDefault="qualified"
+             xmlns:t="http://t.example/">
+    <xs:element name="foo">
+      <xs:complexType>
+        <xs:sequence>
+          <xs:element name="no_type" />
+          <xs:element name="int" type="xs:int" />
+        </xs:sequence>
+      </xs:complexType>
+    </xs:element>
+  </xs:schema>
diff -Naur orig/XML-Validator-Schema/t/test.xsd XML-Validator-Schema/t/test.xsd
--- orig/XML-Validator-Schema/t/test.xsd	2005-10-22 06:06:32.000000000 -0700
+++ XML-Validator-Schema/t/test.xsd	2006-02-01 15:20:50.000000000 -0800
@@ -1,16 +1,16 @@
 <?xml version="1.0" encoding="UTF-8"?>
-  <schema xmlns="http://www.w3.org/2001/XMLSchema">
-    <element name="foo">
-      <complexType>
-        <sequence>
-          <element name="no_type" minOccurs="0" />
-          <element name="int" type="int" minOccurs="0" />
-          <element name="integer" type="integer" minOccurs="0" />
-          <element name="name" type="NMTOKEN" minOccurs="0"  />
-          <element name="string" type="string" minOccurs="0" />
-          <element name="bool" type="boolean" minOccurs="0" />
-          <element name="date" type="dateTime" minOccurs="0" />
-        </sequence>
-      </complexType>
-    </element>
-  </schema>
+  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+    <xs:element name="foo">
+      <xs:complexType>
+        <xs:sequence>
+          <xs:element name="no_type" minOccurs="0" />
+          <xs:element name="int" type="xs:int" minOccurs="0" />
+          <xs:element name="integer" type="xs:integer" minOccurs="0" />
+          <xs:element name="name" type="xs:NMTOKEN" minOccurs="0"  />
+          <xs:element name="string" type="xs:string" minOccurs="0" />
+          <xs:element name="bool" type="xs:boolean" minOccurs="0" />
+          <xs:element name="date" type="xs:dateTime" minOccurs="0" />
+        </xs:sequence>
+      </xs:complexType>
+    </xs:element>
+  </xs:schema>
diff -Naur orig/XML-Validator-Schema/t/two_level.yml XML-Validator-Schema/t/two_level.yml
--- orig/XML-Validator-Schema/t/two_level.yml	2005-10-22 06:06:32.000000000 -0700
+++ XML-Validator-Schema/t/two_level.yml	2006-02-01 15:20:50.000000000 -0800
@@ -2,16 +2,16 @@
 
 --- |
   <?xml version="1.0" encoding="UTF-8"?>
-  <schema xmlns="http://www.w3.org/2001/XMLSchema">
-    <element name="foo">
-      <complexType>
-        <sequence>
-          <element name="bar" minOccurs="0" />
-          <element name="baz" minOccurs="0" />
-        </sequence>
-      </complexType>
-    </element>
-  </schema>
+  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+    <xs:element name="foo">
+      <xs:complexType>
+        <xs:sequence>
+          <xs:element name="bar" minOccurs="0" />
+          <xs:element name="baz" minOccurs="0" />
+        </xs:sequence>
+      </xs:complexType>
+    </xs:element>
+  </xs:schema>
 
 --- |
   <?xml version="1.0" encoding="UTF-8"?>
@@ -27,7 +27,7 @@
     <bif/>
   </foo>
 --- >
-FAIL /unexpected <bif>/
+FAIL /unexpected <{}bif>/
 
 --- |
   <?xml version="1.0" encoding="UTF-8"?>
@@ -45,5 +45,5 @@
     <bar/>
   </foo>
 --- >
-FAIL /'bar' does not match content model/
+FAIL /'{}bar' does not match content model/
 
